10 examples of 'lodash filter array of objects' in JavaScript

Every line of 'lodash filter array of objects' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
45function filterArrayObject(array, filter){
46 var i = 0;
47
48 // array.length is changing
49 for(; i < array.length; i ++){
50 if(!filter.call(array, array[i], i)){
51
52 // the member at the iterator has been removed, so we should move the iterator one step to the left
53 array.splice(i --, 1);
54 }
55 }
56
57 return array;
58};
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

75function filterObjects(arr) {
76 var queryParams = getQueryParams();
77 return arr.filter(function (obj) {
78 var keep = true;
79 if (("type" in obj) && ("type" in queryParams)) keep = (queryParams["type"] === obj["type"]);
80 if ((keep) && ("uid" in obj) && ("uid" in queryParams)) keep = (queryParams["uid"] === obj["uid"]);
81 return keep;
82 });
83}
5function filterObjectByKey(array, object) {
6 return array.reduce((p, v) => {
7 if (object && object[v] !== undefined) {
8 p[v] = object[v];
9 }
10 return p;
11 }, {});
12};
19function filterArray(arr, filter) {
20 var rtn = [];
21 for (var i = 0; i < arr.length; i++) {
22 if (filter.indexOf(i) > -1) {
23 rtn.push(arr[i]);
24 }
25 }
26 return rtn;
27}
72export function filterValues(arrayOfObjects, arrayOfKeys, key="RowKey", caseSensitive=true) {
73 if (caseSensitive) {
74 return arrayOfObjects.filter(o => arrayOfKeys.indexOf(o[key]) > -1);
75 }
76 const keys = arrayOfKeys.map(x => x.toLowerCase());
77 return arrayOfObjects.filter(o => keys.indexOf(o[key].toLowerCase()) > -1);
78}
82function filterUnique(array) {
83 return array.filter((value, idx) => array.indexOf(value) === idx)
84}
165function filter(arr, func) {
166 if (arr.filter) {
167 return arr.filter(func);
168 }
169
170 var result = [ ];
171 for (var i = 0, c = arr.length; i < c; i++) {
172 if (func.call(null, arr[i], i, arr)) {
173 result.push(arr[i]);
174 }
175 }
176
177 return result;
178}
383function filter(arr, cb) {
384 if (arr == null) return [];
385 if (typeof cb !== 'function') {
386 throw new TypeError('braces: filter expects a callback function.');
387 }
388
389 var len = arr.length;
390 var res = arr.slice();
391 var i = 0;
392
393 while (len--) {
394 if (!cb(arr[len], i++)) {
395 res.splice(len, 1);
396 }
397 }
398 return res;
399}
92function filterArray(instance, predicate) {
93 var arrInstance = (instance.constructor === Array) ?
94 instance : __spread(instance);
95 return arrInstance.filter(predicate);
96}
3function filterItems(array) {
4 return array.filter(e => e.constructor.hasLitItemMixin);
5}

Related snippets