खोज…


परिचय

लोदश एक आसान जावास्क्रिप्ट उपयोगिता पुस्तकालय है।

एक संग्रह को फ़िल्टर करें

नीचे दिए गए कोड स्निपेट विभिन्न तरीकों को दिखाते हैं जो आप लॉश का उपयोग करके वस्तुओं की एक सरणी पर फ़िल्टर कर सकते हैं।

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
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow