在不知道父元素的情况下检索子元素



我想知道是否可以获得objet1&objet2而不指定"objet1"&"目标2'?

let tableauObj = [ 
objet1: {name: Albert}, 
objet2: {name: Florence}]

您可以通过数组中对象的索引来引用数组中的对象。单击这些链接以了解有关JavaScript中的对象和数组的更多信息。

let tableauObj = [ 
{name: "Albert"}, 
{name: "Florence"}];
// The object with the name property of "Albert"
// is at index zero of the tableauObj array:
console.log(tableauObj[0].name);
// The object with the name property of "Florence"
// is at index one of the tableauObj array:
console.log(tableauObj[1].name);

最新更新