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

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay