js & for & for of & for in & forEach, break
js for break
https://stackoverflow.com/questions/2641347/short-circuit-array-foreach-like-calling-break
for(let item of str.split(``)) {
if(!Number.isInteger(item * 1)) {
isExistUnNumber = true;
index = str.split(``).indexOf(item);
break;
}
};
// for(let [item, i] of [...str.split(``)].entries()) {
for(let [i, item] of [...str.split(``)].entries()) {
if(!Number.isInteger(item * 1)) {
isExistUnNumber = true;
index = i;
break;
}
};
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/break
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/continue
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch
label
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label
parseInt
demo
https://repl.it/@xgqfrms/js-string-to-number
for(let item of str.split(``)) {
if(!Number.isInteger(item * 1)) {
isExistUnNumber = true;
index = str.split(``).indexOf(item);
break;
}
};
throw error break
自定义error
forEach
for...in
refs
©xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!