Test Automation Stack

We might face a scenario where our response has json object having value — array of objects like below.

“filters”: [
{
“id”: 101,
“name”: “VENDOR”,
“isAllowed”: false
},
{
“id”: 102,
“name”: “COUNTRY”,
“isAllowed”: true
},
{
“id”: 103,
“name”: “MANUFACTURER”,
“isAllowed”: false
}
]

We can get the value in multiple ways, but effective and easiest one is by using array filter > this filters for our condition but again return an array. We can then use spread operator to flatten it and get the property value like below.

Note that we can write a function which returns the value for the given property of an object. This ensures our code is clean and easy to maintain.

Leave a comment

I’m Gurudatt

Profile Pic

With over 12 years of quality assurance experience, i have used various test automation tools and testing concepts and helped organization and teams to speed up testing process effectively. I’m also a Cypress.io Ambassador and BrowserStack Champion.

Let’s connect

Discover more from Test Automation Stack

Subscribe now to keep reading and get access to the full archive.

Continue reading