I have two objects like this:
let obj1 = { slotIDs: ["5e0301f353ee2a0546298f15"] }
let obj2 = { slotIDs: ["5e0301f353ee2a0546298f15", "5e03050453ee2a0546298f1c"] }
I need to merge them inside a single array like this
let newObj = ["5e0301f353ee2a0546298f15", "5e03050453ee2a0546298f1c"]
I have tried using lodash union and map but no luck.
One line of code solution:
let obj1 = { slotIDs: ['5e0301f353ee2a0546298f15'] }
let obj2 = { slotIDs: ['5e0301f353ee2a0546298f15', '5e03050453ee2a0546298f1c'] }
const result = [...new Set([...obj1.slotIDs, ...obj2.slotIDs])]
console.log(result)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With