Wednesday, February 28, 2018

javascript - What is the difference between substr and substring?



What is the difference between



alert("abc".substr(0,2));



and



alert("abc".substring(0,2));


They both seem to output “ab”.


Answer



The difference is in the second argument. The second argument to substring is the index to stop at (but not include), but the second argument to substr is the maximum length to return.



Links?




https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/substr



https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/substring


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...