Answers for "use value of variable as key javascript"

10

variable key name js

//You need to make the object first, then use [] to set it.

var key = "happyCount";
var obj = {};
obj[key] = someValueArray;
myArray.push(obj);
Posted by: Guest on June-19-2020
0

use value of variable as key javascript

var final = [{
  id: 23477234
}];


//add new object to the array using variables as keys AND values
var newArrray = {};
var key = "name";
var value = "John";
newArrray[key] = value;
final.push(newArrray);

/*
final now equals

[{
  id: 23477234,
  name: "John"
}]

*/
Posted by: Guest on May-04-2021

Code answers related to "use value of variable as key javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language