How do you filter an array of key: objects where the value you filter by is in the object?
Asked
Active
Viewed 3,188 times
-3

Phil
- 157,677
- 23
- 242
- 245

Shayan Noruzi
- 23
- 1
- 5
-
3Please provide more information: the array of objects (in code, not just a link), the nested value you want to filter by, and how you want to filter it (eg alphabetically, smallest number to largest, etc). – Ro Milton Sep 15 '21 at 23:09
-
`[ keyMe:object1, keyYou:Object3]` if your array has "literal" key:value elements then this: `KeyedArray["keyMe"]` is all you need. You can use a variable too. [This SO thread](https://stackoverflow.com/q/1144705/463206) might be helpful. – radarbob Sep 15 '21 at 23:23
1 Answers
1
you can do this:
array.filter((item)=>{return item.someKey==='valueYouWant'})
in your example you can do something like this:
const filtered=array.filter((item)=>{return item.categoryId<22})

Mohsen Parvar
- 176
- 7