javascript merge two array remove duplicate values

Solution:

There are two different method 


first method:

var array1 = ["a", "b"]

var array2 = ["b", "c"]

array1 = array1.concat(array2);

console.log(array1);    \\ output: ["a", "b", "c"]



second method:

let array1 = ["a", "b"];

let array2 = ["b", "c"];

let array3 = [...array1,...array2]  \\ output:["a", "b","b", "c"]

let array4=[...new Set(array3)]  \\ hint: using the new Set method removes duplicate values ​​from  array

console.log(array4); \\ output: ["a", "b", "c"]


Comments

Popular posts from this blog

turtle library using create pattern

new amazing pattern using python

wonderful pattern using turtle python