“JavaScript Filter Matriz de objetos” Código de respuesta

Cómo filtrar una matriz de objetos en JavaScript

let arr=[{id:1,title:'A', status:true}, {id:3,title:'B',status:true}, {id:2, title:'xys', status:true}];
//find where title=B
let x = arr.filter((a)=>{if(a.title=='B'){return a}});
console.log(x)//[{id:3,title:'B',status:true}]
Handsome Hedgehog

Se puede utilizar el filtro en objetos en JavaScript

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”} ]
Bright Beaver

Filtrar matriz de javascript

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

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

console.log(result);
White Browed Owl

Cómo filtrar una matriz por lista de objetos en JavaScript

var array = ['Jane','Donna','Jim','Kate']
var objects = [{name:'Jane', age:25},{name:'Jim', age:30}]

//finds the items in the array that have names within the array of objects.
var filtered = array.filter(r => objects.findIndex(obj => obj.name == r) > -1 )
console.log(filtered)
Busy Bird

JavaScript Filter Matriz de objetos

let people = [
  { name: "Steve", age: 27, country: "America" },
  { name: "Jacob", age: 24, country: "America" }
];

let filteredPeople = people.filter(function (currentElement) {
  // the current value is an object, so you can check on its properties
  return currentElement.country === "America" && currentElement.age < 25;
});

console.log(filteredPeople);
// [{ name: "Jacob", age: 24, country: "America" }]
Wicked Wryneck

JavaScript Filter Matriz de objetos

function isBigEnough(value) {
  return value >= 10
}

let filtered = [12, 5, 8, 130, 44].filter(isBigEnough)
// filtered is [12, 130, 44]
Silly Stork

Respuestas similares a “JavaScript Filter Matriz de objetos”

Preguntas similares a “JavaScript Filter Matriz de objetos”

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código