gpt4 book ai didi

javascript - Angularjs 分割数组

转载 作者:行者123 更新时间:2023-12-03 00:46:58 25 4
gpt4 key购买 nike

我有一个看起来像这样的数组

    $scope.A = [

[ "1.31069258855609,103.848649478524", "1.31138534529796,103.848923050526" ],
[ "1.31213221536436,103.848328363879", "1.31288473199114,103.849575392632" ]

];

我想把它做成这样

        $scope.B = [
[
[1.31069258855609,103.848649478524], [1.31138534529796,103.848923050526]
],
[
[1.31213221536436,103.848328363879], [1.31288473199114,103.849575392632]
]
];

PS:抱歉,如果这不是 split ,我不知道如何解决这个问题

代码:

    var latlngs = $scope.polyLineCord.map(subarr => subarr.map(str => str.split(',').map(Number)))
console.log(latlngs)

enter image description here

最佳答案

map 外部数组中的每个项目,然后 .map 每个子数组并用逗号split,以及 map > 再次通过 Number 将字符串转换为数字:

const input = [
["1.31069258855609,103.848649478524", "1.31138534529796,103.848923050526"],
["1.31213221536436,103.848328363879", "1.31288473199114,103.849575392632"]
];
console.log(
input.map(
subarr => subarr.map(
str => str.split(',').map(Number)
)
)
);

关于javascript - Angularjs 分割数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53204619/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com