So, I'm fairly new to programming and I am trying to only display certain objects from a api response array. Besides that, I am using JSReport and Handlebars. Is there a way to filter out the ones with a special value?
Here's an example code:
{
"data": {
"books": {
"author": {
"name": "Book Bookinson",
"books": [
{
"name": "book 1 ",
"stars": "3"
},
{
"address1": "book 2 ",
"phone1": "1"
},
{
"name": "book 3 ",
"stars": "3"
},
{
"address1": "book 4 ",
"phone1": "3"
},
]
},
}
}
So in the code above, I want to filter out so I only get the object with the "stars": "1", and skip the rest. Is there a clean, easy way to do this that I am yet not aware of? I am aware that I can use the object then index through them, but I get a long list of objects that could really need a filter.
Please go easy on me, freshie here!
Not efficient way to do as below but tried my luck using filter and deep cloning object to not alter the main :