10 examples of 'javascript filter array multiple values' in JavaScript

Every line of 'javascript filter array multiple values' 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

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}
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}
99function setFilterValue(filter: Filter, value: any) {
100 filter[filterKey(filter)] = value;
101}
347get filter(): any {
348 return this._filter;
349}
15function uniqueFilter(value, index, array) {
16 return array.indexOf(value) === index;
17}
87function parseSelectFilterValue($valueBlock) {
88 let selector;
89
90 if ($valueBlock.hasClass('multi-value')) {
91 selector = '.multi-select select[name="value[]"]';
92 } else {
93 selector = '.single-select select[name="value"]';
94 }
95
96 let values = $(selector, $valueBlock).val();
97 values = _.flatten([values]);
98
99 if (values.length > 0) {
100 return values;
101 }
102}
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}
177function isValueInArrayOfObjects(selected, key, value) {
178 if (!Array.isArray(selected)) {
179 return selected[key] === value;
180 }
181 for (var _i = 0, selected_1 = selected; _i < selected_1.length; _i++) {
182 var s = selected_1[_i];
183 if (s && s[key] && s[key] === value) {
184 return true;
185 }
186 }
187 return false;
188}
35export function addFilter(filters: Filter[], id: string, value: string): Filter[] {
36 return addFilterRaw(filters, id, `"${value}"`);
37}

Related snippets