Union two array - Node.js Array

Node.js examples for Array:Set Operation

Description

Union two array

Demo Code

Array.prototype.union = function (other) {
  var hash = {};//from  w w w .  j  a va2  s  .c o  m
  for (var i = 0; i < this.length; i++) {
    hash[this[i]] = true;
  }
  for (var j = 0; j < other.length; j++) {
    hash[other[j]] = true;
  }
  return Object.keys(hash);
};

Related Tutorials