pop object from javascript array code example

Example 1: remove an element from array

var colors = ["red", "blue", "car","green"];

// op1: with direct arrow function
colors = colors.filter(data => data != "car");

// op2: with function return value
colors = colors.filter(function(data) { return data != "car"});

Example 2: how to delete an element from a n arry using filter

var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];var filtered = array.filter(function(value, index, arr){ return value > 5;});//filtered => [6, 7, 8, 9]//array => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]

Tags:

Misc Example