cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Math.absolute on array element

manohar
Contributor

Hi there,

I have an array that has negative decimal values. how can I make all the values positive, if theres one?

Thanks
Manohar

5 REPLIES 5

rohithmadhavan
Employee
Employee

@manohar You can use the map Array function:

$array.map(x => Math.abs(x))

Hi @rohithmadhavan. thanks for that.

I actually should have added my array that I want to convert. how can I apply yours to below one?

jsonPath($, โ€œ$[โ€˜invoice-chargesโ€™][*].totalโ€)

Thanks
Manohar

Assuming jsonPath($, โ€œ$[โ€˜invoice-chargesโ€™][*].totalโ€) returns an array:

jsonPath($, โ€œ$[โ€˜invoice-chargesโ€™][*].totalโ€).map(x => Math.abs(x))

Hi @rohithmadhavan, looks like some issue in there. please see the screenshot.

image

Thanks
Manohar