What does substr? With and without it?

http://jsfiddle.net/fqk7wu59/

Like above example I try without it and do same?

What is advantage to use it?

Thanks!

Not sure I fully understand the question. substr() is being used to truncate the string - substr(0, 500) starts at the first character and trims the string to the first 500 characters.

the purpose of substr() is to act on a string, and given a starting index and a length, to return the substring from that original string. There is a warning on the MDN page about this though - it is not a core feature of the javascript language, and thus may, at some point, be removed.

Instead, the MDN suggests using String.substring(), which is slightly different - rather than taking a starting index and length, substring() takes a starting index and an ending index. Similar, but in your case off by one. This, too, returns the given substring of the original string.

Are you saying you would prefer not to use these functions?

1 Like