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);
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);
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"
}]
*/
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us