10 examples of 'javascript filter object by key value' in JavaScript

Every line of 'javascript filter object by key value' 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
1export default function filterObject (obj, key) {
2 for (var i in obj) {
3 if (!obj.hasOwnProperty(i)) continue
4 if (typeof obj[i] === 'object') {
5 filterObject(obj[i], key)
6 } else if (i === key) {
7 delete obj[key]
8 }
9 }
10 return obj
11}
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

99function setFilterValue(filter: Filter, value: any) {
100 filter[filterKey(filter)] = value;
101}
159function filter(value) {
160 // Allow tabbing out of the search input and skipping the sort links
161 // when there is a search value.
162 sortColumns.forEach((link) => {
163 if (value) {
164 link.tabIndex = -1;
165 } else {
166 link.removeAttribute('tabIndex');
167 }
168 });
169
170 // Test the input against the file/folder name.
171 let even = false;
172 fileNames.forEach((name, i) => {
173 if (!value || name.toLowerCase().includes(value.toLowerCase())) {
174 const className = even ? 'even' : '';
175 rows[i].className = className;
176 even = !even;
177 } else {
178 rows[i].className = 'hidden';
179 }
180 });
181}
200function filterKeys(key) {
201 var excluded = [
202 'mappable',
203 'parent',
204 'collection',
205 origin.idAttribute,
206 origin.typeAttribute
207 ];
208 return excluded.indexOf(key) < 0 && kepts.indexOf(key) > -1;
209}
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}
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};
36function valueFilter(key, value, operator) {
37 return operator('p[' + JSON.stringify(key) + ']', JSON.stringify(value));
38}
1function findKey(obj, value) {
2 for (const k in obj) {
3 if (obj[k] === value) {
4 return k;
5 }
6 }
7
8 return null;
9}
26export function keyBy(value, key) {
27 let obj = {}
28
29 value.forEach(function(element) {
30 obj[element[key]] = element
31 })
32
33 return obj
34}
9function filter(value) {
10 value = value.toLowerCase();
11 return viable.filter(function(v) {
12 return v.name.toLowerCase().indexOf(value) !== -1;
13 }).map(function(v) {
14 return {
15 title: v.name,
16 value: v.name
17 };
18 });
19}

Related snippets