list of all the properties of a string object in JavaScript

·

3 min read

Here is a list of all the properties of a string object in JavaScript:

  • constructor: Returns the function that created the string object's prototype.

  • length: Returns the number of characters in the string.

  • prototype: Allows the addition of properties to an object.

Note that constructor and prototype are not specific to string objects and are inherited from the Object prototype.

In addition to these properties, there are several string-specific methods available on a string object that can be used to manipulate and transform strings. These methods are:

  • charAt(): Returns the character at a specified index.

  • charCodeAt(): Returns the Unicode value of the character at a specified index.

  • codePointAt(): Returns the Unicode code point of the character at a specified index.

  • concat(): Joins two or more strings and returns a new string.

  • endsWith(): Returns true if the string ends with a specified character(s), otherwise false.

  • includes(): Returns true if the string contains a specified character(s), otherwise false.

  • indexOf(): Returns the index of the first occurrence of a specified character(s) in a string.

  • lastIndexOf(): Returns the index of the last occurrence of a specified character(s) in a string.

  • localeCompare(): Compares two strings in the current locale.

  • match(): Searches a string for a match against a regular expression, and returns the matches as an array.

  • normalize(): Returns the Unicode Normalization Form of the string.

  • padEnd(): Pads the end of a string with a specified character(s) until it reaches a specified length.

  • padStart(): Pads the beginning of a string with a specified character(s) until it reaches a specified length.

  • repeat(): Returns a new string with a specified number of copies of the original string.

  • replace(): Searches a string for a specified value or regular expression, and replaces it with a new value.

  • search(): Searches a string for a specified value or regular expression, and returns the index of the match.

  • slice(): Extracts a section of a string and returns a new string.

  • split(): Splits a string into an array of substrings based on a specified separator.

  • startsWith(): Returns true if a string starts with a specified character(s), otherwise false.

  • substr(): Extracts a section of a string and returns a new string.

  • substring(): Extracts a section of a string and returns a new string.

  • toLocaleLowerCase(): Converts a string to lowercase in the current locale.

  • toLocaleUpperCase(): Converts a string to uppercase in the current locale.

  • toLowerCase(): Converts a string to lowercase.

  • toString(): Returns the string.

  • toUpperCase(): Converts a string to uppercase.

  • trim(): Removes whitespace from both ends of a string.

  • valueOf(): Returns the primitive value of a string.

These methods allow you to perform a wide range of operations on strings, such as searching, replacing, splitting, and formatting.