I have a data structure like this :
var someObject = {
'part1' : {
'name': 'Part 1',
'size': '20',
'qty' : '50'
},
'part2' : {
'name': 'Part 2',
'size': '15',
'qty' : '60'
},
'part3' : [
{
'name': 'Part 3A',
'size': '10',
'qty' : '20'
}, {
'name': 'Part 3B',
'size': '5',
'qty' : '20'
}, {
'name': 'Part 3C',
'size': '7.5',
'qty' : '20'
}
]
};
And I would like to access the data using these variable :
var part1name = "part1.name";
var part2quantity = "part2.qty";
var part3name1 = "part3[0].name";
part1name should be filled with someObject.part1.name 's value, which is "Part 1". Same thing with part2quantity which filled with 60.
Is there anyway to achieve this with either pure javascript or JQuery?
http://jsfiddle.net/alnitak/hEsys/: http://jsfiddle.net/alnitak/hEsys/
Watch video Accessing nested JavaScript objects and arrays by string path online without registration, duration hours minute second in high quality. This video was added by user Code Samples 31 March 2024, don't forget to share it with your friends and acquaintances, it has been viewed on our site 96 once and liked it 1 people.