javascript create object key from variable
//You need to make the object first, then use [] to set it.
var key = "happyCount";
var obj = {};
obj[key] = someValueArray;
myArray.push(obj);//For ES6 and Babel
{
[yourKeyVariable]: "yourValue",
}
// ES5 Alternative
// Create the object first, then use [] to set your variable as a key
var yourObject = {};
yourObject[yourKeyVariable] = "yourValue";
Also in JavaScript:
- copy php array to javascript
- js require is not defined
- check if element is visible jquery
- how to update node modules
- angularjs iframe src binding
- Unexpected end of JSON input while parsing near '...fcd15e632426a1be","ta'
- how to create angular project in visual studio code windows 10
- sort array by string length javascript
- how to execute something after ajax call
- clear cache javascript
- javascript email validation
- how to create array in javascript
- display none in jquery
- asp net core use newtonsoft json
- How many different types of JS alerts do we have?
- return only specific attributes when making query mongoose
- await on observable
- express js continous GET /json/version
- sleeping in js
- get current week number javascript
- core.js:12799 Can't bind to 'ngForIn' since it isn't a known property of 'ng-container'.
- javascript add row to table
- return value from javascript function
- react strict mode