Filtering array data in javascript ES6

2 years ago23k times

Filtering array data in Javascript ES6 with following code


const names = ['Hello', 'John', 'Teena', 'amber', 'meller', 'abuture','anna'];


const filterednames = names.filter(name => name.length <= 5)


console.log(filterednames); // ['Hello', 'John', 'Teena', 'amber', 'anna']


Other answers

Numbers can filtered with the following code


const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];

const filter = arr.filter((number) => number > 5);
console.log(filter); // [6, 7, 8, 9]

Try the below code to filter data from array in javascript


var digits = [10, 30, 26, 5, 15,2,4,6,8];


var alldigits = digits.filter(function(digit) {
  return digit > 7;
});


console.log(alldigits); // [10, 30, 26, 15, 8]

Add Answer

Add a codeAdd Code
Remove adsremove

Latest codes

view all

Latest Snippets

view all