可以通過以下方法循環遍歷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數組并取出需要的值。