如何将字符串数组的数组转换为数字数组的数组?

How to convert an Array of Arrays of strings to an Array of Arrays of numbers?

我有一个字符串数组,如下所示:

 [    
 0: Array(1)
    0: Array(6)
        0:  [5.379856, 43.252967]
        1:  [5.422988, 43.249466]
        2:  [5.425048, 43.245153]
        3:  [5.383804, 43.239838]
        4:  [5.399856, 43.212967]
        5:  [5.379856, 43.252967]
1: Array(1)
    0: Array(6)
        0:  [5.39014, 43.279295]
        1:  [5.393069, 43.279249]
        2:  [5.391814, 43.278421]
        3:  [5.390709, 43.278749]
        4:  [5.3909, 43.2785]
        5:  [5.39014, 43.279295]
 ]

值是字符串。我想将每个值转换成一个数字。 有人可以解释一下如何在没有循环的情况下完成吗?

亲切的问候,

数组中有数字而不是字符串。但是如果你有字符串,你可以使用 map() and Number() 将它们转换为数字。

var data = [
  [
    ["5.379856", "43.252967"],
    ["5.422988", "43.249466"],
    ["5.425048", "43.245153"],
    ["5.383804", "43.239838"],
    ["5.399856", "43.212967"],
    ["5.379856", "43.252967"]
  ],
  [
    ["5.39014", "43.279295"],
    ["5.393069", "43.279249"],
    ["5.391814", "43.278421"],
    ["5.390709", "43.278749"],
    ["5.3909", "43.2785"],
    ["5.39014", "43.279295"]
  ]
];

data = data.map(arr => arr.map(item => item.map(value => Number(value))));

console.log(data);