Add property to each object in the array

后端 未结 3 1335
执念已碎
执念已碎 2021-01-25 04:04

I\'m trying to add a property to each object in the array:

var capitals = [{
    country: \"What\'s the capital of Ecuador?\",
    choices: [\"Quito\", \"Caracas         


        
3条回答
  •  無奈伤痛
    2021-01-25 04:38

    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
    }];
    for(i in capitals) {
      capitals[i].global = true;
    }
    console.log(capitals)
    

提交回复
热议问题