# Assertion value for all arrays

**URL:** <https://community.postman.com/t/assertion-value-for-all-arrays/44859>\
**Category:** Help Hub\
**Created:** [March 7, 2023, 8:57pm UTC](https://community.postman.com/t/assertion-value-for-all-arrays/44859 "2023-03-07T20:57:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aerospace-operator-9](https://avatars.discourse-cdn.com/v4/letter/a/a9adbd/32.png) [@aerospace-operator-9](https://community.postman.com/u/aerospace-operator-9)\
**Post date:** [March 7, 2023, 8:57pm UTC](https://community.postman.com/t/assertion-value-for-all-arrays/44859/1 "2023-03-07T20:57:45Z")

</div>

Hi!  
I´m trying to validate a value that appears in many results arrays. It is not possible to repeat the test every time, in this case I have 50 results, but this number is not a known value.  
I have checked in help different solutions but without any success.  
Could anyone help me with this? Thanks in advance!

I would need to check this value \*\*jsondata.data[_for each array].elasticScore_  
This is my current test:

var jsondata = JSON.parse(responseBody);

pm.test(“Elastic Score \> 0 \<= 1”, function () {  
var jsondata = pm.response.json();  
pm.expect(jsondata.data[0].elasticScore).to.be.greaterThan(0);  
});

pm.test(“Elastic Score \> 0 \<= 1”, function () {  
var jsondata = pm.response.json();  
pm.expect(jsondata.data[1].elasticScore).to.be.greaterThan(0);  
});

pm.test(“Elastic Score \> 0 \<= 1”, function () {  
var jsondata = pm.response.json();  
pm.expect(jsondata.data[2].elasticScore).to.be.greaterThan(0);  
});

pm.test(“Elastic Score \> 0 \<= 1”, function () {  
var jsondata = pm.response.json();  
pm.expect(jsondata.data[3].elasticScore).to.be.greaterThan(0);  
});

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [March 8, 2023, 10:15am UTC](https://community.postman.com/t/assertion-value-for-all-arrays/44859/2 "2023-03-08T10:15:06Z")

</div>

Parse your response directly to the data array.

You are also using the old method for parsing.

Use the following instead.

```auto
const array = pm.response.json().data

```

Once you have an array, you can use a forEach loop.

[JavaScript Array forEach() Method (w3schools.com)](https://www.w3schools.com/jsref/jsref_foreach.asp)

```auto
response.forEach(element => 
    pm.test(`Elastic Score ${element.elasticScore} > 0 <= 1`, () => {
        pm.expect(element.elasticScore).to.be.greaterThan(0);
    })
);

```

Use backticks and a string literal in the test case name so you can customise the name.

[JavaScript Template Literals (w3schools.com)](https://www.w3schools.com/JS//js_string_templates.asp)

On a side note, your test name, and your assertion don’t fully align. The assertion is “greater than zero”, but your test case name is “greater than zero and less than or equal 1”. If that is the actual test, then you need to update your assertion to match.

---

<div class="post-metadata">

**Author:** ![aerospace-operator-9](https://avatars.discourse-cdn.com/v4/letter/a/a9adbd/32.png) [@aerospace-operator-9](https://community.postman.com/u/aerospace-operator-9)\
**Post date:** [March 15, 2023, 2:31pm UTC](https://community.postman.com/t/assertion-value-for-all-arrays/44859/3 "2023-03-15T14:31:18Z")

</div>

Thanks for your help! It works perfect!!!

I have already changed the test name because I have copied from other one…

 ![Screenshot 2023-03-15 at 15.28.50](https://us1.discourse-cdn.com/getpostman/original/3X/7/6/760fabb7b44ba5672678c8b932311bf328b457e6.jpeg)
