showing results for - "javascript create object key from variable"
Malone
14 Jan 2017
1//You need to make the object first, then use [] to set it.
2
3var key = "happyCount";
4var obj = {};
5obj[key] = someValueArray;
6myArray.push(obj);
Lotta
27 Aug 2018
1//For ES6 and Babel
2{
3    [yourKeyVariable]: "yourValue",
4}
5
6// ES5 Alternative
7// Create the object first, then use [] to set your variable as a key
8var yourObject = {};
9
10yourObject[yourKeyVariable] = "yourValue";
queries leading to this page
pass key as variable name javascript in objectjavascript string to object keyjavascript push variable object into array with keyjavascript create object key from variablejavascript object key from variablejavascript create object with string keyjs use variable as object keycreate new object with key value in javascriptset object key javascriptvariable in object key javascriptjavascript object key with variable valuejavascript assign valu to objetc with keynode js variable value as object keyobject key variablejavascript object key as variableassign key to object javascriptcreate object with key variable javascriptcustom object key name in javascriptadd variable inobject keyjs create object key from variablevariable key name javascriptjavascript add object key from variableput string key as a variable javascriptjavascript use variable as object keyobject key as a variablecreate object with key and value javascriptjs add object element with variable keymake key as variable in javascript objectjavascript variables as object keyjs add variable value as keyobject key from variable javascriptmake variable key in obj in jscreate object with variable key javascriptjavascript get from object with variable keyjs object using variable as key js object variable as keyobject set keyjs object keys variablehow to use variable as object key in typescriptjavascript object key as variable valuehow to use variable key in js objectcreate key object from variable javascripthow to use string as object key javascriptjavascript create object key from variable