When type equals all, I need to combine two arrays into one. I have the code, but it gets the wrong result。
const arr = [{value: 'aa'}, {value: 'bb'}];
const arr2 = [{type: 'all'}, {type: 'text', value: 'a2'}, {type: 'all'}]
arr.forEach((item, index) => {
arr2.forEach((items, indexs) => {
if (items.type === 'all') {
items.value = arr[index].value
}
})
})
console.log(arr2)
I hope to get this result
arr2 = [{type: 'all', value: 'aa'}, {type: 'text', value: 'a2'}, {type: 'all', value: 'bb'}]
console.log(arr2)