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/
On this page of the site you can watch the video online Accessing nested JavaScript objects and arrays by string path with a duration of hours minute second in good quality, which was uploaded by the user Code Samples 31 March 2024, share the link with friends and acquaintances, this video has already been watched 96 times on youtube and it was liked by 1 viewers. Enjoy your viewing!