可以使用ES6中的Array.prototype.map()方法和Array.prototype.join()方法来实现:

const arr = [{id: 1}, {id: 2}, {id: 3}];
const ids = arr.map(item => item.id).join(',');
console.log(ids); // "1,2,3"

首先使用map()方法将每个对象的id属性提取出来,形成一个新的数组,然后使用join()方法将这个数组转换成以逗号分隔的字符串。

es6 将数组id 查出来并转成逗号分隔

原文地址: https://www.cveoy.top/t/topic/gZZ3 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录