gpt4 book ai didi

javascript - 将带有逗号的字符串转换为带有逗号的数组(甚至只是带有逗号的数字)

转载 作者:行者123 更新时间:2023-12-02 23:30:03 31 4
gpt4 key购买 nike

我在 MaxMSP 中使用 JS

我想获取一个字符串输出(由逗号分隔的单个斐波那契数字)并将其转换为数组或数字,保留空格和逗号,但使用“双引号”

我在这里尝试了很多东西,但不幸的是我仍然在用头撞墙。

autowatch = 1;

inlets = 2;
outlets = 2;


function msg_int(num){

var a = 1;
var b = 0, temp;


while (num >= 0){
temp = a;
a = a + b;
b = temp;
num--;
outlet(0, b);


var n = temp;
digits = n.toString().replace(/(\d{1})/g,'$1, ')
outlet(1, digits);


}
return b;


}

输入数字是14第一个导出(0)号码是 610第二个导出(1)是“6,1,0,”

我希望第二个导出为 6, 1, 0,

最佳答案

var result = '"6, 1, 0,"'.replace(/['"]+/g, '')
console.info(result);

关于javascript - 将带有逗号的字符串转换为带有逗号的数组(甚至只是带有逗号的数字),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56551832/

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