Hello Friends 👋,
Welcome To Infinitbility! ❤️
In this article, you will learn the Best practice to merge arrays in javascript or merge arrays without duplicate values.
Let’s Start today topic Merge arrays in javascript
Javascript concat function
Javascript provide concat function to merge arrays let’s undertand with Merge two arrays example.
1let array1 = [1, 2, 3];2let array2 = [2, 3, 4];34let array3 = array1.concat(array2);5console.log(array3);67/*8 * Output9 * [1, 2, 3, 2, 3, 4]10 */
Javascript Merge without dublicate values
Using JavaScript concat we know it will merge same value also but you need only unique values show or merge in third array.
Let’s undertand with Merge arrays in javascript without dublication example.
1let array1 = [1, 2, 3];2let array2 = [2, 3, 4];34let array3 = [...new Set([...array1,...array2])]5console.log(array3);67/*8 * Output9 * [1, 2, 3, 4]10 */
Thanks For Reading…
Follow me on Twitter
Join our email list and get notified about new content
No worries, I respect your privacy and I will never abuse your email.
Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.