filter item in array javascript code example

Example 1: js filter array of objects by value

var heroes = [
	{name: “Batman”, franchise:DC},
	{name: “Ironman”, franchise: “Marvel”},
	{name: “Thor”, franchise: “Marvel”},
	{name: “Superman”, franchise:DC}
];

var marvelHeroes =  heroes.filter(function(hero) {
	return hero.franchise == “Marvel”;
});

// [ {name: “Ironman”, franchise: “Marvel”}, {name: “Thor”, franchise: “Marvel”} ]

Example 2: filter javascript array

var words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];

const result = words.filter(word => word.length > 6);

console.log(result);

Example 3: filter out arrays js

let newArray = array.filter(function(item) {
  return condition;
});

Example 4: javascript array filter

var newArray = array.filter(function(item) {
  return condition;
});

Example 5: js filter array

const filterArray=(a,b)=>{return a.filter((e)=>{return e!=b})}

let array = ["a","b","","d","","f"];

console.log(filterArray(array,""));//>> ["a","b","d","f"]