Underscore.js Arrays: Intersection

by tylerbrownhenry

HTML

<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<a target="parent" href="http://underscorejs.org/#intersection">Learn More</a>

JavaScript

var arr = [1,654,6,4,87,7845,5645,5645435,"blue",654645654645,6,3423433,57767676];
var arr2 = [66564,56432432,"blue",445563,5,67,36,76,23,87,6,5645,64564,32437,78768,654];
var arr3 = [5645,564,32,67,87,6,"blue",4,1,5,23,78768,345,6,45342,34234,32423,654,546];
var arr4 = [543543,4534,45345,"blue",5345,5345,434,5435,"red",6,"green","apples",654];

var testIntersection = _.intersection(arr,arr2,arr3,arr4);

console.log(testIntersection);
//[654, 6, "blue"]
//Finds all of entries that are shared by all of the arrays