gpt4 book ai didi

javascript - 迭代一个数字中的数字,只要它是相同的数字

转载 作者:行者123 更新时间:2023-11-28 11:34:36 25 4
gpt4 key购买 nike

我需要循环遍历一个数字的数字,直到该数字存在差异,然后输出数字长度:

例如:

0000123

所以输出应该是 3。

(消除0000并输出123)

我该如何解决这个问题?

最佳答案

尝试在字符串上循环,直到发现差异:

var num="001234",i,max=num.length,output;
for(i=1;i<max;i+=1){
if(num[i]!== num[i-1]){
output = num.substring(i,max);
break;
}
}

alert(output);

关于javascript - 迭代一个数字中的数字,只要它是相同的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26969189/

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