我有这个JSON数组:
const arr = [
{ data: '250', name: 'john' },
{ data: '251', name: 'john' }
]:
我怎么能从它得到,一个新的数组有[250, 251]
?
我不能解决这个问题。
let arr = [ { data: '250', name: 'john' }, { data: '251', name: 'john' } ];
let result = arr.map((x) => x.data);
console.log(result);
let arr = [
{ data: "250", name: "john" },
{ data: "251", name: "john" },
];
let result = arr.map((x) => x.data);
console.log(result);
let list = [];
for (let i = 0; i < arr.length; i++) {
list.push(arr[i].data);
}
console.log(list);