1var colors=["red","green","blue","yellow"];
2//loop back-words through array when removing items like so:
3for (var i = colors.length - 1; i >= 0; i--) {
4 if (colors[i] === "green" || colors[i] === "blue") {
5 colors.splice(i, 1);
6 }
7}
8//colors is now  ["red", "yellow"]
1const colors=["red","green","blue","yellow"];
2let index = colors.length - 1;
3while (index >= 0) {
4 if (['green', 'blue'].indexOf(colors[index]) > (-1)) {
5 colors.splice(index, 1);
6 }
7 index -= 1;
8}
1var array = [1, 2, 3, 4];var evens = _.remove(array, function(n) { return n % 2 === 0;});console.log(array);// => [1, 3]console.log(evens);// => [2, 4]
1var ar = [1, 2, 3, 4, 5, 6];ar.pop(); // returns 6console.log( ar ); // [1, 2, 3, 4, 5]
1var ar = [1, 2, 3, 4, 5, 6];ar.length = 4; // set length to remove elementsconsole.log( ar ); // [1, 2, 3, 4]
1var arr1 = [1, 2, 3, 4, 5, 6];var arr2 = arr1; // Reference arr1 by another variable arr1 = [];console.log(arr2); // Output [1, 2, 3, 4, 5, 6]