JavaScript Program to Merge Two Arrays and Remove Duplicate Items Using Spread Syntax and Set Full Project For Beginners

 

 

script.js

 

 

// program to merge and remove duplicate value from an array

function getUniqueAfterMerge(arr1, arr2){

    // merge two arrays
    let arr = [...arr1, ...arr2];

    // removing duplicate
    let uniqueArr = [...new Set(arr)];

    console.log(uniqueArr);
}

const array1 = [1, 2, 3];
const array2 = [2, 3, 5]

// calling the function
getUniqueAfterMerge(array1, array2);

Leave a Reply