I'm trying to do union of different arrays:
const info1 = {id: 1}
const info2 = {id: 2}
const info3 = {id: 3}
const array1 = [info1, info2]
const array2 = [info1, info3]
const array3 = [info2, info3]
const union = [...new Set([...array1, ...array2, ...array3])]
console.log(union)
It's possible in my code that some or all array1, array2, array3 can be null, this is not shown in the code above.
However when one or more of them are null I get the error for example if array1 was assigned to null: array1 is not iterable.
How can I prevent getting this error?
nullcheck before the union.nullcheck that I would need to add?nullyou need to deal with it somehow.