キーが表示されているインスタンスの数を調べようとしていて、その値も取得しようとしています。多次元オブジェクトからキーとその値を取得する方法
たとえば、tpoint
のキーが何度表示されたのかを、packageContents
としましょう。次に、それぞれtpoint
からカンマ区切りのtouches
のリストを取得しようとしています。このようなもの:
tpInstance = 2;
[tpoint = 21、tpoint = 9]
誰も私がこれを入手することができます方法を知っていますか?
var packageContents = {
'packages': {
'package': {
'price': '32',
'name': 'Gold Bundle Package',
'calendar': {
'type': '2year',
'color': 'Brushed Nickel',
},
'tpoint': {
'type': 'Gold',
'touches': '21',
'years': '7',
}
},
'package': {
'price': '23',
'name': 'Bronze Bundle Package',
'calendar': {
'type': '2year',
'color': 'Brushed Nickel',
},
'tpoint': {
'type': 'Bronze',
'touches': '9',
'years': '7',
}
}
}
};
var tpInstance = Object.keys(package).length;
console.log(tpInstance);