gpt4 book ai didi

javascript - 使用 JavaScript 将项目添加到数组中的每个对象

转载 作者:行者123 更新时间:2023-11-30 11:58:06 26 4
gpt4 key购买 nike

我正在制作一种 Trivial Pursuit 游戏。我有成千上万的问题和答案;看下面的例子:

var trivialPursuitCards = [
{
question: "What nationality was Chopin?",
answer: ["American", "Polish", "German", "Czech"],
difficulty: 2
},
{
question: "Who cut Van Gogh's ear?",
answer: ["His sister", "His brother", "Himself", "He was born that way"],
difficulty: 2
}
];

现在我只需要为每张卡片添加一个属性,即:rightAnswer: undefined

为所有卡片完成此操作的最佳方法是什么?

最佳答案

for(var i=0; i<trivialPursuitCards.length; i++) {
trivialPursuitCards[i].rightAnswer = undefined;
}

https://jsfiddle.net/o0pa4z0w/

关于javascript - 使用 JavaScript 将项目添加到数组中的每个对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37363243/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com