![](/img/trans.png)
[英]Calling String.prototype.substring with Infinity as second parameter
[英]Question regarding JavaScript String.prototype.substring
var alpha = "ABCDEFG"; var result = alpha.substring(0, 5); document.write(result);
問題是,為什么答案是ABCDE(0,4)而不是ABCDEF(0,5)。 編程中的所有數字都以零開頭,對嗎?
String.prototype.substring
最多包含兩個參數。 一個代表開始索引,一個代表結束索引(可選)。 當起始索引包含在新字符串中時,結束索引將被排除。 當4是結束索引時,該字符將被排除,您將看到字符0-3
請閱讀https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.