We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent fe96b7a commit f3e68adCopy full SHA for f3e68ad
1 file changed
05 - Objects-And-Functions/searchAnyValue.js
@@ -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