Friday, December 27, 2024
Google search engine
HomeLanguagesJavascriptJavaScript String Reference

JavaScript String Reference

In this article, we will learn JavaScript Strings and their properties and methods with brief description. JavaScript Strings are used for storing and manipulating text content. It can contain zero or more characters within single or double quotes, like “Geeksforneveropen” or ‘Geeksforneveropen’.

Syntax:

String(object)

Example: In this example, we will return the Date() object’s string value.

Javascript




function stringLength() {
    const str = "neveropen";
  
    console.log("String Length: " + str.length);
}
  
stringLength();


 

Output:

String Length: 13

The complete list of JavaScript Strings has listed below:

 

JavaScript String Constructor: In JavaScript, a constructor gets called when an object is created using the new keyword.

Constructor

Description

Example

String() Convert the value of an object to a string.
Try

JavaScript String Properties: A JavaScript property is a member of an object that associates a key with a value. There is no static property in the string only instance property.

  • Instance Property: An instance property is a property that has a new copy for every new instance of the class.

Instance Properties

Description

Example

length Find out the size of that object
Try
constructor Return the string constructor function for the object.
Try

JavaScript String Methods: JavaScript methods are actions that can be performed on objects. There are two types of String methods in JavaScript.

  • Static Method: If the method is called using the string class itself then it is called a static method.

Static Methods

Description

Example

fromCharCode() Create a string from the given sequence of UTF-16 code units.
Try
fromCodePoint() Return a string or an element for the given sequence of code point values (ASCII value).
Try
  • Instance Method: If the method is called on an instance of a string then it is called an instance method.

Instance Methods

Description

Example

at() Find the character at the specified index.
Try
anchor() Creates an anchor element that is used as a hypertext target.
Try
charAt() Returns that character at the given index of the string.
Try
charCodeAt() Returns a Unicode character set code unit of the character present at the index in the string.
Try
codePointAt() Return a non-negative integer value i.e, the code point value of the specified element.
Try
concat() Join two or more strings together in JavaScript.
Try
endsWith() Whether the given string ends with the characters of the specified string or not.
Try
includes() Returns true if the string contains the characters, otherwise, it returns false.
Try
indexOf() Finds the index of the first occurrence of the argument string in the given string.
Try
lastIndexOf() Finds the index of the last occurrence of the argument string in the given string.
Try
localeCompare() Compare any two elements and returns a positive number
Try
match() Search a string for a match against any regular expression.
Try
matchAll() Return all the iterators matching the reference string against a regular expression.
Try
normalize() Return a Unicode normalization form of a given input string.
Try
padEnd() Pad a string with another string until it reaches the given length from rightend.
Try
padStart() Pad a string with another string until it reaches the given length from leftend.
Try
repeat() Build a new string containing a specified number of copies of the string.
Try
replace() Replace a part of the given string with some another string or a regular expression
Try
replaceAll() Returns a new string after replacing all the matches of a string with a specified string/regex.
Try
search() Search for a match in between regular expressions and a given string object.
Try
slice() Return a part or slice of the given input string.
Try
split() Separate given string into substrings using a specified separator provided in the argument.
Try
startsWith() Check whether the given string starts with the characters of the specified string or not.
Try
substr() Returns the specified number of characters from the specified index from the given string.
Try
substring() Return the part of the given string from the start index to the end index.
Try
toLowerCase() Converts the entire string to lowercase.
Try
toLocaleLowerCase() Returns the calling string value converted to a lowercase letter.
Try
toLocaleUpperCase() Returns the calling string value converted to a uppercase letter.
Try
toUpperCase() Converts the entire string to uppercase.
Try
toString() Return the given string itself.
Try
trim() Remove the white spaces from both ends of the given string.
Try
trimEnd() Remove white space from the end of a string.
Try
trimStart() Remove white space from the start of a string.
Try
valueOf() Return the value of the given string.
Try

RELATED ARTICLES

Most Popular

Recent Comments