Aryan PrajapatKnowledge Contributor
How do you add a key value pair in javascript
How do you add a key value pair in javascript
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Questions | Answers | Discussions | Knowledge sharing | Communities & more.
There are two possible solutions to add new properties to an object.
Let’s take a simple object to explain these solutions.
var object = {
key1: value1,
key2: value2,
};
1. Using dot notation: This solution is useful when you know the name of the property
object.key3 = “value3”;
2.Using square bracket notation: This solution is useful when the name of the property is dynamically determined.
obj[“key3”] = “value3”;