gpt4 book ai didi

javascript - 获取 JSON 对象数组中的值

转载 作者:行者123 更新时间:2023-12-02 17:59:16 30 4
gpt4 key购买 nike

我有一个 JSON 对象数组,如下所示:

[
{ name: "tom", text: "tasty" },
{ name: "tom", text: "tasty" },
{ name: "tom", text: "tasty" },
{ name: "tom", text: "tasty" },
{ name: "tom", text: "tasty" }
]

我想循环它们并在列表中回显它们。我该怎么做?

最佳答案

你的意思是这样的吗?

 var a = [
{ name: "tom", text: "tasty" },
{ name: "tom", text: "tasty" },
{ name: "tom", text: "tasty" },
{ name: "tom", text: "tasty" },
{ name: "tom", text: "tasty" }
];

function iter() {
for(var i = 0; i < a.length; ++i) {
var json = a[i];
for(var prop in json) {
alert(json[prop]);
// or myArray.push(json[prop]) or whatever you want
}
}
}

关于javascript - 获取 JSON 对象数组中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1988320/

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