Answers for "use variable for object key"

4

for key value in object javascript

for (const [key, value] of Object.entries(object1)) {
  console.log(`${key}: ${value}`);
}
Posted by: Guest on December-09-2020
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
8

javascript create object key from variable

//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";
Posted by: Guest on September-28-2020
2

js variable for key obj

{
    [yourKeyVariable]: someValueArray,
}
Posted by: Guest on November-16-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language