DEV Community

Harshit Kedia
Harshit Kedia

Posted on

Useful javascript nuggets

Revised javascript objects, noted some useful points:

We can omit the quotes for single-word string properties, like make in the following example-
const anotherObject = {
make: "Ford",
5: "five",
"model": "focus"
};
*Notice 5, we can also use numbers as properties.

If the property of the object we are trying to access has a space in its name, we need to use bracket notation, ex: myObj["Space Name"];

We can add new properties to existing JavaScript objects the same way you would modify them. Ex: ourDog.bark = "bow-wow"; // bark property was not declared initially

delete properties from objects like this: delete ourDog.bark;

someObject.hasOwnProperty(someProperty) returns true or false depending on if the property is found on the object or not

*In a code, records[id][prop].push(value) was giving error because the array was not defined in some cases, so changed the code to:
const arr = records[id][prop] || []
arr.push(value)
records[id][prop]=arr

Neon image

Build better on Postgres with AI-Assisted Development Practices

Compare top AI coding tools like Cursor and Windsurf with Neon's database integration. Generate synthetic data and manage databases with natural language.

Read more →

Top comments (0)

👋 Kindness is contagious

Dive into this insightful write-up, celebrated within the collaborative DEV Community. Developers at any stage are invited to contribute and elevate our shared skills.

A simple "thank you" can boost someone’s spirits—leave your kudos in the comments!

On DEV, exchanging ideas fuels progress and deepens our connections. If this post helped you, a brief note of thanks goes a long way.

Okay