Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript set object key by variable

/* FOR ES6 and Babel */
{
    [yourKeyVariable]: someValueArray,
}  

//for older versions

var key = "happyCount";
var obj = {};
obj[key] = someValueArray;
myArray.push(obj);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #set #object #key #variable
ADD COMMENT
Topic
Name
7+6 =