我有下面的数组
const a1 = [1,2,3];
并希望将其转换为
const b1 = [{id:1},{id:2},{id:3}];
有没有一种快速的方式来做JavaScript
使用Array.map()
const a1 = [1,2,3]; const b1 = a1.map(val => ({id: val})); console.log(b1);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
点击生成二维码
我来说两句