Answers for "javascript get object value dynamically"

9

javascript dynamically access object property

var person ={"first_name":"Billy","last_name":"Riley"};
var property_name="first_name";
alert(person[property_name]); //Dynamically access object property with bracket notation
Posted by: Guest on July-31-2019
2

dynamic properties instead javascript

var foo = { pName1 : 1, pName2 : [1, {foo : bar }, 3] , ...}

var name = "pName"
var num  = 1;

foo[name + num]; // 1

// -- 

var a = 2;
var b = 1;
var c = "foo";

foo[name + a][b][c]; // bar
Posted by: Guest on June-23-2020
0

javascript get object value dynamically

var something = {
  bar: 'foo'
};
var foo = 'bar';

// both x = something[foo] and something[foo] = x work as expected
console.log(something[foo]);
console.log(something.bar)
Posted by: Guest on May-16-2021

Code answers related to "javascript get object value dynamically"

Code answers related to "Javascript"

Browse Popular Code Answers by Language