怎么把数组中的img转换成img123的形式 addtime111 img 123 addtime222 img 34 addtime333 img 567
可以使用map方法和split方法来实现:
const arr = [
{
addtime:"111",
img: "1,2,3"
},
{
addtime:"222",
img: "3,4"
},
{
addtime:"333",
img: "5,6,7"
}
];
const newArr = arr.map(item => {
return {
addtime: item.addtime,
img: item.img.split(',')
}
});
console.log(newArr);
输出结果:
[
{
addtime: "111",
img: ["1", "2", "3"]
},
{
addtime: "222",
img: ["3", "4"]
},
{
addtime: "333",
img: ["5", "6", "7"]
}
]
原文地址: http://www.cveoy.top/t/topic/cRik 著作权归作者所有。请勿转载和采集!