Skip to content

Commit f3e68ad

Browse files
authored
Create searchAnyValue.js
1 parent fe96b7a commit f3e68ad

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const arr = [{
2+
name: 'xyz',
3+
grade: 'xs'
4+
}, {
5+
name: 'yaya',
6+
grade: 'xa'
7+
}, {
8+
name: 'xf',
9+
frade: 'dd'
10+
}, {
11+
name: 'a',
12+
grade: 'b'
13+
}];
14+
15+
16+
function filterIt(arr, searchKey) {
17+
return arr.filter(obj => Object.keys(obj).some(key => obj[key].includes(searchKey)));
18+
}
19+
20+
console.log("find 'x'", filterIt(arr,"x"));
21+
console.log("find 'a'", filterIt(arr,"a"));
22+
console.log("find 'z'", filterIt(arr,"z"));

0 commit comments

Comments
 (0)