Name
String: support for strings — ECMAScript v1: Object → String
Constructor
new String(s
) // Constructor function String(s
) // Conversion function
Arguments
-
s
The value to be stored in a String object or converted to a primitive string.
Returns
When String( )
is used as
a constructor with the new
operator, it returns a String object, which holds the string
s
or the string representation of
s
. When the String( )
constructor is used without
the new
operator, it simply
converts s
to a primitive string and
returns the converted value.
Properties
-
length
The number of characters in the string.
Methods
-
charAt( )
Extracts the character at a given position from a string.
-
charCodeAt( )
Returns the encoding of the character at a given position in a string.
-
concat( )
Concatenates one or more values to a string.
-
indexOf( )
Searches the string for a character or substring.
-
lastIndexOf( )
Searches the string backward for a character or substring.
-
localeCompare( )
Compares strings using locale-specific ordering.
-
match( )
Performs pattern matching with a regular expression.
-
replace( )
Performs a search-and-replace operation with a regular expression.
-
search( )
Searches a string for a substring that matches a regular expression.
-
slice( )
Returns a slice or substring of a string.
-
split( )
Splits a string into an array of strings, breaking at a specified delimiter string or regular expression.
-
substr( )
Extracts a substring of a string; a variant of
substring( )
.-
substring( )
Extracts a substring of a string. ...
Get JavaScript: The Definitive Guide, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.