var myArray = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]; var diffArray = [3, 4, 5]; // the lodash way var cool = _.difference(myArray, diffArray); // Pure JS var notCool = []; for (var i = 0; i < myArray.length; i++) { if (diffArray.indexOf(myArray[i]) == -1) { notCool.push(myArray[i]); } } //display it on page document.getElementById("cool").innerHTML = cool; document.getElementById("not-cool").innerHTML = notCool;
Lodash result: <p id="cool"></p> Pure JS result: <p id="not-cool"></p>