js variable for key obj
//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";{
[yourKeyVariable]: someValueArray,
}
Also in JavaScript:
- javascript get first property of object
- check array values equal js
- generate random password
- javascript detect click outside element
- tableau javascript
- how to block special characters in javascript
- js delete all array items
- for in loops javascript
- base64 decode javascript
- next.js with material ui
- loop through map in js
- json parse string
- check if element is visible
- angular event emitter
- multiple line string in jquery
- javascript collision detection
- @editorjs/list window not defined
- how to flatten array in javascript using foreach loop
- javascript generate random color site:stackoverflow.com
- get url react
- p5 js lines
- age validation jquery
- video recorder using webrtc and javascript
- créer composant react