0

In python I could do something like:

seconds = [i[1] for i in my_giant_2d_matrix]

How can I do this in JS if my data structure is, e.g.:

  ["2017-08-01 17:05:57.27-08", 0.9685023945717632],
  ["2017-08-01 17:05:57.27-08", 1.8976437986779295],
  ["2017-08-01 17:05:57.27-08", 7.834808973859426],
  ["2017-08-01 17:05:57.27-08", 9.24775164641563],
  ["2017-08-01 17:05:57.27-08", 9.736525537982486],
  ["2017-08-01 17:05:57.27-08", 2.923580004727238],
  ["2017-08-01 17:05:57.27-08", 6.727439970979467],
  ["2017-08-01 17:05:57.27-08", 7.018190596386605],
  ["2017-08-01 17:05:57.27-08", 0.9126885492079035],
  ["2017-08-01 17:05:57.27-08", 10.42473448771042],
  ["2017-08-01 17:05:57.27-08", 8.150613247753153],
  ["2017-08-01 17:05:57.27-08", 7.603327591939451]...

I want the floats for all these (second value). Thanks.

2 Answers 2

4

You can use map:

var matrix = [["2017-08-01 17:05:57.27-08", 0.9685023945717632],
  ["2017-08-01 17:05:57.27-08", 1.8976437986779295],
  ["2017-08-01 17:05:57.27-08", 7.834808973859426],
  ["2017-08-01 17:05:57.27-08", 9.24775164641563],
  ["2017-08-01 17:05:57.27-08", 9.736525537982486],
  ["2017-08-01 17:05:57.27-08", 2.923580004727238],
  ["2017-08-01 17:05:57.27-08", 6.727439970979467],
  ["2017-08-01 17:05:57.27-08", 7.018190596386605],
  ["2017-08-01 17:05:57.27-08", 0.9126885492079035],
  ["2017-08-01 17:05:57.27-08", 10.42473448771042],
  ["2017-08-01 17:05:57.27-08", 8.150613247753153],
  ["2017-08-01 17:05:57.27-08", 7.603327591939451]];
  

console.log(
  matrix.map(x => x[1])
)

Sign up to request clarification or add additional context in comments.

Comments

0

seconds = array.map(el => el[1])

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.