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 Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →