javascript push object into array with variable key

Solutions on MaxInterview for javascript push object into array with variable key by the best coders in the world

showing results for - "javascript push object into array with variable key"
Lilly
07 May 2019
1//Normal Javascript
2var key = "happyCount";
3var obj = {};
4obj[key] = someValueArray;
5myArray.push(obj);
6
7//OR
8
9//If you're able to use ES6 and Babel, you can use this new feature:
10
11{
12    [yourKeyVariable]: someValueArray,
13}