Get certain values of strings in array

Hi all,

I am trying to get the value between the ‘()’ of every record inside the array.

[
{ “betroffene IT Systeme”:[
“Ardoq·(431)”
“SnapLogic·(580)”
]
}
]
So that I get an array:
[ {
“betroffene IT Systeme”:[
“431”
“580”
]
} ]

My expressions language is still a bit rusty…

Hi,

You can use the below expression.

$[‘betroffene IT Systeme’].map(x => x.substring(x.indexOf(“(”)+1, x.indexOf(“)”)))

1 Like

This also works and seems a little easier to understand. Instead of searching for the indexes of the open and close parenthesis and using a substring, it just removes everything that isn’t a numeric value. Great solution provided by nsingam, but in the spirit of offering you options, I thought I would share this one with you too. Definitely there are more than 1 way to skin a cat (horrible expression).

$[‘betroffene IT Systeme’].map(x => x.replace(/[^0-9]/g, ‘’))

2 Likes

Hi @alex.panganiban.guild

Thank you for your answer, much appreciated. That I haven’t tought about that also. Because I always only need the numbers.

Regards

Jens