内の各オブジェクトにプロパティを追加します。私は、配列内の各オブジェクトにプロパティを追加しようとしている配列
var capitals = [{
country: "What's the capital of Ecuador?",
choices: ["Quito", "Caracas", "Panama", "Loja"],
corAnswer: 0
}, {
country: "What is the capital of China?",
choices: ["Shanghai", "Beijing", "Ghangzou", "Hong Kong"],
corAnswer: 0
}];
はなるはずです。
var capitals = [{
country: "What's the capital of Ecuador?",
choices: ["Quito", "Caracas", "Panama", "Loja"],
corAnswer: 0,
global: true
}, {
country: "What is the capital of China?",
choices: ["Shanghai", "Beijing", "Ghangzou", "Hong Kong"],
corAnswer: 0,
global: true
}];
配列は、複数のオブジェクトを含めることができます。どのような機能が必要ですか?
を使用することができ、私はその意志オブジェクト –
@VladimirStarkovの元の配列を変化させないために '.map'を使用することをお勧めしたいです不要にクローンを作成する。このコンテキストは 'map'を必要としません、私は信じています。 –
OPは文脈について何も言わなかった、 'map'を使って' forEach'の暗黙のデータフローではなく明示的なデータフローを提供しました –