Substring vs Substr | Javascript

The substring() method extracts the characters from a string, between two specified indices, and returns the new sub string. This method extracts the characters in a string between “from” and “to”, not including “to” itself.

string.substring(from, to)

The substr() method extracts the characters from a string, beginning at “start” and through the specified number of character, and returns the new sub string.

string.substr(start,length)

References: here and here

Advertisements

One Response to “Substring vs Substr | Javascript”

  1. hfrmobile Says:

    substring() vs. substr() … I “love” such naming “confusions” 😉

    What happens to both functions when “index out of rage” occurs?


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: