How to get the union of two sets in javascript -
this question has answer here:
- getting union of 2 arrays in javascript 20 answers
say have 2 sets (arrays):
a = [1,2,3]; b = [2,3,5];
and want 1,2,3,5 out only.
what terse way this? or, failing that, way this?
var = [1,2,3]; var b = [2,3,5]; //concat both arrays [1,2,3,2,3,5] var result = a.concat(b).filter(function(value, index, self) { //array unique return self.indexof(value) === index; }); console.log(result); //[1, 2, 3, 5];
Comments
Post a Comment