Answers for "javascript push object into array with variable key"

0

javascript push object into array with variable key

//Normal Javascript
var key = "happyCount";
var obj = {};
obj[key] = someValueArray;
myArray.push(obj);

//OR

//If you're able to use ES6 and Babel, you can use this new feature:

{
    [yourKeyVariable]: someValueArray,
}
Posted by: Guest on December-17-2020

Code answers related to "javascript push object into array with variable key"

Code answers related to "Javascript"

Browse Popular Code Answers by Language