在python中我可以做类似的事情:
seconds = [i[1] for i in my_giant_2d_matrix]
如果我的数据结构是,例如:
,如何在JS中执行此操作 ["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]...
我想要所有这些浮动(第二个值)。感谢。
答案 0 :(得分:3)
您可以使用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])
)
答案 1 :(得分:1)
seconds = array.map(el => el[1])