Accessing nested JavaScript objects and arrays by string path

preview_player
Показать описание
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 part3name1 = "part3[0].name";

Is there anyway to achieve this with either pure javascript or JQuery?
Рекомендации по теме
welcome to shbcf.ru