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

Image of Wix Studio

2025: Your year to build apps that sell

Dive into hands-on resources and actionable strategies designed to help you build and sell apps on the Wix App Market.

Get started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay