gpt4 book ai didi

javascript - 将字符串javascript数组转换为整数javascript数组

转载 作者:行者123 更新时间:2023-12-03 11:24:42 24 4
gpt4 key购买 nike

我有一个数组,

var array = ["1","2","3","4","5"];

然后我需要转换为

var array = [1,2,3,4,5];

我如何转换?

最佳答案

将其映射到 Number 函数:

var array = ["1", "2", "3", "4", "5"];
array = array.map(Number);
array; // [1, 2, 3, 4, 5]

关于javascript - 将字符串javascript数组转换为整数javascript数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32964649/

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