gpt4 book ai didi

javascript - 如何使用字符串中的数据来更新 javascript 对象?

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

我有以下数据数组:

var ans = 
[
{"text":"x","response":false},
{"text":"y","response":false},
{"text":"z","response":true}
];

var correct = "010"; // I need to add this to the array ans

任何人都可以建议我如何使用正确变量中的数据添加到数组中,以便:

var ans = 
[
{"text":"x","response":false,"correct":false},
{"text":"y","response":false,"correct":true},
{"text":"z","response":true,"correct":false}
];

最佳答案

for(var i=0; i< ans.length; i++) {
ans[i].correct = correct.charAt(i) == "1";
}

关于javascript - 如何使用字符串中的数据来更新 javascript 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24925467/

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