Create and object and add five key values pair to it in JavaScript:
Developer can use below snippet create and add 5 key-value pairs in it.
var obj = {};// an empty object has created
for(var i = 1; i<=5; i++){ // A loop has added to add key- values in above object
obj['number'+i] = i; //here we are using Squire brackets [] to add keys & after assignment symbol values. here values are numbers
}
console.log(obj);
Output:
Comments
Post a Comment