這個問題在這里已經有了答案: 從物件陣列中,將屬性的值提取為陣列 24 個答案 3 分鐘前關閉。
const data = [{
"hello":'thameem',
"age":24
},
{
"hello":'thameem',
"age":25
}];
console.log(data);
我需要所有年齡值
uj5u.com熱心網友回復:
let data = [{ "hello":'thameem', "age":24 }, { "hello":'thameem', "age":25 }];
// will give you an array to ages
data = data?.map(item => item.age)
uj5u.com熱心網友回復:
用于.map創建陣列:
const ages = data.map((d) => d.age);
console.log(ages);
如果您不需要新陣列而只想訪問該屬性,您還可以使用.forEach:
data.forEach((d) => {
// do something with your data
}
uj5u.com熱心網友回復:
常量值 = Object.values(data); 常量鍵 = Object.keys(data);
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/526436.html
