Forum Discussion

ionutbarna's avatar
ionutbarna
New Contributor II
5 years ago

Change certain values inside an Array

Hello,

I have this json:

{
        "a": "Hello Word",
        "b": 1,
        "c": "some",
        "d": 10,
        "nested": [{
            "m": "hey",
            "o": 10,
            "p": "hello",
            "q": 100
        }]
}

I am trying to multiply each number field by 10 and the output structure needs to be the same.
So far I’ve managed to get it worked for an Object using: $.mapValues((value, key) => !isNaN(value) ? value * 10 : value) but I don’t really know how can I do that for Arrays.

Any tips?

Thank you!

5 Replies