Gathering detailed insights and metrics for object-array-filter
Gathering detailed insights and metrics for object-array-filter
Gathering detailed insights and metrics for object-array-filter
Gathering detailed insights and metrics for object-array-filter
os-filter-obj
Filter an array of objects to a specific OS
object.omit
Return a copy of an object excluding the given key, or array of keys. Also accepts an optional filter function as the last argument.
obop
MongoDB-style object operators makes array manipulation easy: where/order/update/view
filter-object-array
Filter an array of objects with an object
Filters an array of objects by matching a field's value in each object to a search term. Returns filtered array.
npm install object-array-filter
Typescript
Module System
Node Version
NPM Version
TypeScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
1 Stars
8 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Jul 21, 2021
Latest Version
1.0.4
Package Id
object-array-filter@1.0.4
Unpacked Size
17.86 kB
Size
4.61 kB
File Count
6
NPM Version
6.14.4
Node Version
12.16.3
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
Filters an array of objects by compariing a field's value in each object to a search term. The following operators can be used: "eq" | "ne" | "lt" | "gt" | "lte" | "gte". Returns a promise of a filtered array. Field values must be strings, numbers or booleans.
Run npm install --save object-array-filter
1const find = require('object-array-filter'); 2 3/** 4 * @param search object 5 * @param array an array of object with the same properties 6 * @param key <optional> object key to perform comparison. 7 * @param comparison <optional> comparison operator to use. 8 * @returns {Promise<object[] | []>} Returns filtered array 9 */ 10 11 12 13const testArray = [ 14 { color: "black", size: 2, big: false }, 15 { color: "pink", size: 3, big: false }, 16 { color: "black", size: 3, big: false }, 17 { color: "pink", size: 14, big: true} 18]; 19 20const size = 3; 21const color = 'black'; 22const big = true; 23 24const testing = async () => { 25 try { 26 const filteredSize = await find.default({ size }, testArray); 27 const filteredColor = await find.default({ color }, testArray); 28 const filteredNotBig = await find.default({ big }, testArray); 29 console.log({ filteredSize, filteredColor, filteredBig }); 30 } catch (error) { 31 console.log(error); 32 } 33}; 34 35//Run function 36testing(); 37 38/* expected output: { 39 filteredSize: [ 40 { color: 'pink', size: 3, big: false }, 41 { color: 'black', size: 3, big: false } 42 ], 43 filteredColor: [ 44 { color: 'black', size: 2, big: false }, 45 { color: 'black', size: 3, big: false } 46 ], 47 filteredBig: [ { color: 'pink', size: 14, big: true } ] 48} */ 49 50/* 51NB: Variable name should match the name of the field in the object. 52If the variable name does not match the field name, the following syntax must be used 53 */ 54const color2 = 'pink' 55find.default({ color2 }, testArray, "color") 56 .then((filtered) => console.log(filtered)) 57 .catch((error) => console.log(error)); 58 59/* expected output: [ { color: 'pink', size: 3 }, { color: 'pink', size: 14 } ] */ 60 61//NB: The default operator is 'eq'. If you wish to use another operator, below are some examples. 62const testingOperators = async () => { 63 try { 64 const filteredLessThanOrEqual3 = await find.default({ size }, testArray, "size", "lte"); 65 const filteredGreaterThan3 = await find.default({ size }, testArray, "size", "gt"); 66 const filteredNotBlack = await find.default({ color }, testArray, "color", "ne"); 67 const filteredNotBig = await find.default({ big }, testArray, "big", "ne"); 68 console.log({ filteredLessThanOrEqual3, filteredGreaterThan3, filteredNotBlack, filteredNotBig }); 69 } catch (error) { 70 console.log(error); 71 } 72}; 73 74testingOperators(); 75 76/* expected output: { 77 filteredLessThanOrEqual3: [ 78 { color: 'black', size: 2, big: false }, 79 { color: 'pink', size: 3, big: false }, 80 { color: 'black', size: 3, big: false } 81 ], 82 filteredGreaterThan3: [ { color: 'pink', size: 14, big: true } ], 83 filteredNotBlack: [ 84 { color: 'pink', size: 3, big: false }, 85 { color: 'pink', size: 14, big: true } 86 ], 87 filteredNotBig: [ 88 { color: 'black', size: 2, big: false }, 89 { color: 'pink', size: 3, big: false }, 90 { color: 'black', size: 3, big: false } 91 ] 92} */ 93
1import find from 'object-array-filter'; 2 3/** 4 * @param search object 5 * @param array an array of object with the same properties 6 * @param key <optional> object key to perform comparison. 7 * @param comparison <optional> comparison operator to use. 8 * @returns {Promise<object[] | []>} Returns filtered array 9 */ 10 11 12 13const testArray = [ 14 { color: "black", size: 2, big: false }, 15 { color: "pink", size: 3, big: false }, 16 { color: "black", size: 3, big: false }, 17 { color: "pink", size: 14, big: true} 18]; 19 20const size = 3; 21const color = 'black'; 22const big = true; 23 24const testing = async () => { 25 try { 26 const filteredSize = await find({ size }, testArray); 27 const filteredColor = await find({ color }, testArray); 28 const filteredNotBig = await find({ big }, testArray); 29 console.log({ filteredSize, filteredColor, filteredBig }); 30 } catch (error) { 31 console.log(error); 32 } 33}; 34 35//Run function 36testing(); 37 38/* expected output: { 39 filteredSize: [ 40 { color: 'pink', size: 3, big: false }, 41 { color: 'black', size: 3, big: false } 42 ], 43 filteredColor: [ 44 { color: 'black', size: 2, big: false }, 45 { color: 'black', size: 3, big: false } 46 ], 47 filteredBig: [ { color: 'pink', size: 14, big: true } ] 48} */ 49
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
8 existing vulnerabilities detected
Details
Reason
no SAST tool detected
Details
Reason
Found 0/8 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More