Navigate back to the homepage

Best practice to merge arrays in Javascript

Infinitbility
JavaScript
April 21st, 2021 · 1 min read
Best practice to merge arrays in Javascript

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];
3
4let array3 = array1.concat(array2);
5console.log(array3);
6
7/*
8 * Output
9 * [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];
3
4let array3 = [...new Set([...array1,...array2])]
5console.log(array3);
6
7/*
8 * Output
9 * [1, 2, 3, 4]
10 */

Thanks For Reading…

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

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.

More articles from Infinitbility

how to format all partition of hdd

how to format all partition of hdd

Format all partition of hdd using HDDLF

April 20th, 2021 · 1 min read
how to remove your computer password

how to remove your computer password

Remove your forgotten password from windows

April 19th, 2021 · 1 min read
© 2020–2021 Infinitbility
Disclaimer
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]