Net-informations.com
SiteMap  | About    

substr() Vs. substring()

The JavaScript string is an object that represents a sequence of characters. The substr() method extracts parts of a string, beginning at the character at the specified position, and returns the specified number of characters. The substring() method returns the part of the string between the start and end indexes, or to the end of the string.

Syntax

start: The position where to start the extraction, index starting from 0.

length: The number of characters to extract (optional).

example

The above code would return "Script".

Syntax

start: The position where to start the extraction, index starting from 0.

end: The position (up to, but not including) where to end the extraction (optional).

example

The above code would return "Script"

substr() Vs. substring()

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. Moreover, substr() accepts a negative starting position as an offset from the end of the string. substring() does not.









net-informations.com (C) 2018    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.