Is there any way to push elements from array2 if array1 doesn't include them already, without using a for loop iterating each element?
Ex:
array1 = [1, 2, 3] array2 = [1, 3, 5, 6] So my result want to be this:
array1 = [1, 2, 3, 5, 6] Is there any way to push elements from array2 if array1 doesn't include them already, without using a for loop iterating each element?
Ex:
array1 = [1, 2, 3] array2 = [1, 3, 5, 6] So my result want to be this:
array1 = [1, 2, 3, 5, 6] array1 = [1, 2, 3] array2 = [1, 3, 5, 6] // Use set to remove duplicates, concat to merge the two arrays result = [...new Set(array1.concat(array2))] console.log(result) Remove duplicates
https://www.javascripttutorial.net/array/javascript-remove-duplicates-from-array/
Concat
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat