add data to an object key array javascript code example
Example 1: map add key to object in array javascript
const newArr = [
{name: 'eve'},
{name: 'john'},
{name: 'jane'}
].map(v => ({...v, isActive: true}))
Example 2: 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,
}