Node.js
Lodash
Buscar..
Introducción
Lodash es una útil biblioteca de utilidades de JavaScript.
Filtrar una colección
El fragmento de código a continuación muestra las diversas formas en que puede filtrar en una matriz de objetos usando lodash.
let lodash = require('lodash');
var countries = [
{"key": "DE", "name": "Deutschland", "active": false},
{"key": "ZA", "name": "South Africa", "active": true}
];
var filteredByFunction = lodash.filter(countries, function (country) {
return country.key === "DE";
});
// => [{"key": "DE", "name": "Deutschland"}];
var filteredByObjectProperties = lodash.filter(countries, { "key": "DE" });
// => [{"key": "DE", "name": "Deutschland"}];
var filteredByProperties = lodash.filter(countries, ["key", "ZA"]);
// => [{"key": "ZA", "name": "South Africa"}];
var filteredByProperty = lodash.filter(countries, "active");
// => [{"key": "ZA", "name": "South Africa"}];
Modified text is an extract of the original Stack Overflow Documentation
Licenciado bajo CC BY-SA 3.0
No afiliado a Stack Overflow