将两个字符串中的数据重组成一个数组对象
例:
'e6b8206dfa6e,2888fa3a20e9d,4ad39d93a88,f45e88b346f8d9' // str1
'krystal,kurttotem,Rose,Jack' // str2
// 由上边的数据组成如下格式:
[ { name: 'xxx', id: 'xxx' }, { name: 'xxx', id: 'xxx' }, { name: 'xxx', id: 'xxx' } ]
let idsStr = 'e6b8206dfa6e,2888fa3a20e9d,4ad39d93a88,f45e88b346f8d9'
let nameStr = 'krystal, kurttotem, Rose, Jack'
let idsArr = idsStr.split(',')
let nameArr = nameStr.split(',')
let newArr = idsArr.map((item, index) => ({
'name': nameArr[index],
'id': item
}))
console.log(newArr)
image.png
网友评论