变为这种纯数据数组
{18 8 5 4 2}
你这是一个对象数组,你遍历数组取每个元素的id属性就行
data = [{'id':18},{'id':8},{'id':5},{'id':4},{'id':2}];
arr = [];
for(let i=0;i<data.length;i++){
arr.push(data[i].id);
}
console.log(arr);
https://www.runoob.com/json/json-stringify.html
使用 JSON.stringify() 方法处理以上数据,将其转换为字符串:
var myJSON = JSON.stringify(obj);
const arr = [{ id: 18 }, { id: 8 }, { id: 5 }, { id: 4 }, { id: 2 }];
let result = arr.map((item) => item.id);
console.log("result", result);