Node.js
Lodash
Zoeken…
Invoering
Lodash is een handige JavaScript-hulpprogramma-bibliotheek.
Filter een verzameling
Het onderstaande codefragment toont de verschillende manieren waarop u op een reeks objecten kunt filteren met behulp van 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
Licentie onder CC BY-SA 3.0
Niet aangesloten bij Stack Overflow