“Cómo filtrar la lista de objetos por una matriz en JavaScript” Código de respuesta

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

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

var array = ['cat','dog','fish','goat']  
var objects = [{pet:'cat', color:'brown'},{pet:'dog', color:'black'},{pet:'gecko', color:'green'}]

//finds the objects that match something in the list with the key pet.
var filteredObjects = objects.filter(function(obj){
    return array.indexOf((obj.pet).toString()) > -1;
  });
console.log(filteredObjects)
Busy Bird

JavaScript Filter Matriz de objetos por matriz

var arr = [1,2,3,4],
    brr = [2,4],
    res = arr.filter(f => !brr.includes(f));
console.log(res);
Powerful Penguin

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 “Cómo filtrar la lista de objetos por una matriz en JavaScript”

Preguntas similares a “Cómo filtrar la lista de objetos por una matriz en JavaScript”

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código