可以通过以下方法循环遍历JSON数组并取值:
const jsonArray = [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}];
for (let i = 0; i < jsonArray.length; i++) {
console.log(jsonArray[i].name);
console.log(jsonArray[i].age);
}
const jsonArray = [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}];
jsonArray.forEach(item => {
console.log(item.name);
console.log(item.age);
});
const jsonArray = [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}];
for (const item of jsonArray) {
console.log(item.name);
console.log(item.age);
}
这些方法可以用来循环遍历JSON数组并取出需要的值。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:sql json数组取值的方法是什么