gpt4 book ai didi

javascript - 将逗号分隔字符转换为逗号分隔整数

转载 作者:行者123 更新时间:2023-11-28 11:35:49 26 4
gpt4 key购买 nike

我想转换字符串"1,2,3,4"1,2,3,4在 jQuery/JavaScript 中。我该如何转换这个?我可以使用任何内置函数来实现相同的功能吗?

最佳答案

JSON.parse让一切变得简单。

var str = "1,2,3,4";
var numbers = JSON.parse("[" + str + "]");
console.log(numbers);

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

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