What is the difference between
(之间有什么区别)
alert("abc".substr(0,2));
and
(和)
alert("abc".substring(0,2));
They both seem to output “ab”.
(他们似乎都输出“ ab”。)
The difference is in the second argument.
(区别在于第二个参数。)
substring
substr
(substring的第二个参数是要在(但不包括)处停止的索引,而substr的第二个参数是要返回的最大长度。)
Links?
(链接?)
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/substr
(https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/substr)
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/substring
(https://developer.mozilla.org/zh-CN/JavaScript/Reference/Global_Objects/String/substring)
1.4m articles
1.4m replys
5 comments
56.9k users