Skip to content

Instantly share code, notes, and snippets.

@kenpeter
Created May 15, 2019 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenpeter/d2ebd58ebc481e847e8356e030c78006 to your computer and use it in GitHub Desktop.
Save kenpeter/d2ebd58ebc481e847e8356e030c78006 to your computer and use it in GitHub Desktop.
How to union two array in javascript
// arr1
var a = [34, 35, 45, 48, 49];
// arr2
var b = [48, 55];
// spread a, spread b
// into Set obj (unique)
// sreapd again, inject to arr
var union = [...new Set([...a, ...b])];
console.log(union);
From:
https://stackoverflow.com/questions/3629817/getting-a-union-of-two-arrays-in-javascript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment