JavaScript将[{ID: 'PLANNER01'}, {ID: 'PLANNER01'}, {ID: 'PLANNER01'}]转换为['PLANNER01', 'PLANNER01', 'PLANNER01'] - 代码示例
可以使用map方法对数组中的每个对象进行遍历,然后取出ID的值,放入一个新的数组中。
const arr = [{ID: 'PLANNER01'}, {ID: 'PLANNER01'}, {ID: 'PLANNER01'}];
const result = arr.map(obj => obj.ID);
console.log(result); // ['PLANNER01', 'PLANNER01', 'PLANNER01']
原文地址: https://www.cveoy.top/t/topic/pTiR 著作权归作者所有。请勿转载和采集!