0

I've got a .json file that looks like this:

[
    [
        1513814400000,
        0.8433
    ]
]

Now, my question is this: I need to modify every 2nd value in this file, i.e:

0.8433 -> 8.433

I already wrote a javascript that loads the file using jQuery, however I'm not sure how I can go through the file and edit these values. The manipulation is always the same, for example:

new value = old value * 10

Any tips on how I could do this?

2
  • array[0][0]*10 ?? Commented Mar 18, 2018 at 13:46
  • Can do this with multiple different loop approaches. A for loop, Array#forEach, Array#map etc Commented Mar 18, 2018 at 13:47

1 Answer 1

1

Lets say:

var array = [[1,2], [2,3],....[n,m]];

Then you can do:

array = array.map(element => {
  if(element[1]) element[1] = element[1] * 10;
  return element;
});

The result will be:

array = [[1,20], [2,30],....[n,m*10]];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.