I have this first array, at the end of each item it has numerical value.
const arr = ["abc#1","def#2","z#1", "z#2"]
I have to map it with below array
const arrObj = [{
name: 'abc'
},{
name: 'def'
},{
name: 'z'
}]
to populate a new property value that has boolean in array
result = [{
name: 'abc',
value: [true, false]
},{
name: 'def',
value: [false, true]
},{
name: 'z',
value: [true, true]
}]
I'm stuck at doing multiple iteration but failed to produce above result.
const arr = ["abc#1","def#2","z#1", "z#2"]
let arrObj = [{
name: 'abc'
},{
name: 'def'
},{
name: 'z'
}]
const raw = arr.map(o => o.split('#')[0])
const key = arr.map(o => o.split('#')[1])
arrObj = arrObj.map(o => {
console.log('raw', raw)
if(raw.includes(o.name)) {
console.log('key', key)
console.log(o.name)
}
return {
...o,
value: []
}
})
{ value: 'z', value: [true, true] }twovalue:is invalid)valuearray come from. Could you be more specific on that? Like, why the first array is[true, false]and the second is[false, true]and the last is[true, true]name: 'z'be included inarrObj?