There are two ways to dynamically access object property:-
1.Dot Notation
2.Bracket notation
var eg = {first1: "101", second: "202"};
console.log(eg.first1);
var key1 = first+1; alert(eg1); // first1
console.log(eg[key1]);
The dot notation eg.first1 and Bracket notation eg[key1] is similar except for the fact that the bracket notation will also work if key1 comes from a variable, function return value, etc. where key1 is your dynamically constructed property key.
You can also access the same with :- eg[first1]
If you have used a variable to store property name,then you need to use Bracket notation to access it.
0 Comment(s)