JavaScript String Methods

¡Supera tus tareas y exámenes ahora con Quizwiz!

String.fromCharCode()

String.fromCharCode(n1, n2, ..., nX). The fromCharCode() method converts Unicode values into characters. Note: This is a static method of the String object, and the syntax is always String.fromCharCode().

String.charAt()

string.charAt(index). The charAt() method returns the character at the specified index in a string. The index of the first character is 0, the second character is 1, and so on. Tip: The index of the last character in a string is string.length-1, the second last character is string.length-2, and so on

String.charCodeAt()

string.charCodeAt(index). The charCodeAt() method returns the Unicode of the character at the specified index in a string. The index of the first character is 0, the second character 1, and so on. Tip: You can use the charCodeAt() method together with the length property to return the Unicode of the last character in a string. The index of the last character is -1, the second last character is -2, and so on

String.lastIndexOf()

string.lastIndexOf(searchvalue,start). The lastIndexOf() method returns the position of the last occurrence of a specified value in a string. Note: The string is searched from the end to the beginning, but returns the index starting at the beginning, at postion 0. This method returns -1 if the value to search for never occurs. Note: The lastIndexOf() method is case sensitive!

String.localeCompare()

string.localeCompare(compareString). The localeCompare() method compares two strings in the current locale. The locale is based on the language settings of the browser. The localeCompare() method returns a number indicating whether the string comes before, after or is equal as the compareString in sort order.

String.match()

string.match(regexp). The match() method searches a string for a match against a regular expression, and returns the matches, as an Array object. Read more about regular expressions in our RegExp Tutorial and our RegExp Object Reference. Note: If the regular expression does not include the g modifier (to perform a global search), the match() method will return only the first match in the string. This method returns null if no match is found.

String.replace()

string.replace(searchvalue,newvalue). The replace() method searches a string for a specified value, or a regular expression, and returns a new string where the specified values are replaced.

String.search()

string.search(searchvalue). The search() method searches a string for a specified value, and returns the position of the match. The search value can be string or a regular expression. This method returns -1 if no match is found.

String.slice()

string.slice(start,end). The slice() method extracts parts of a string and returns the extracted parts in a new string. Use the start and end parameters to specify the part of the string you want to extract. The first character has the position 0, the second has position 1, and so on. Tip: Use a negative number to select from the end of the string.

String.split()

string.split(separator,limit). The split() method is used to split a string into an array of substrings, and returns the new array. Tip: If an empty string ("") is used as the separator, the string is split between each character. Note: The split() method does not change the original string.

String.substr()

string.substr(start,length). The substr() method extracts parts of a string, beginning at the character at the specified position, and returns the specified number of characters. Tip: To extract characters from the end of the string, use a negative start number (This does not work in IE 8 and earlier). Note: The substr() method does not change the original string.

String.substring()

string.substring(start,end). 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 "start" and "end", not including "end" itself. If "start" is greater than "end", this method will swap the two arguments, meaning str.substring(1,4) == str.substring(4,1). If either "start" or "stop" is less than 0, it is treated as if it were 0. Note: The substring() method does not change the original string.

String.toLowerCase()

string.toLowerCase(). The toLowerCase() method converts a string to lowercase letters. Note: The toLowerCase() method does not change the original string.

String.toString()

string.toString(). The toString() method returns the value of a String object.

String.toUpperCase()

string.toUpperCase(). The toUpperCase() method converts a string to uppercase letters. Note: The toUpperCase() method does not change the original string.

String.trim()

string.trim(). The trim() method removes whitespace from both sides of a string. Note: The trim() method does not change the original string.

String.concat()

string.concat(string1, string2, ..., stringX). The concat() method is used to join two or more strings. This method does not change the existing strings, but returns a new string containing the text of the joined strings.

String.indexOf()

string.indexOf(searchvalue,start). The indexOf() method returns the position of the first occurrence of a specified value in a string. This method returns -1 if the value to search for never occurs. Note: The indexOf() method is case sensitive.

String.length

string.length. The length property returns the length of a string (number of characters). The length of an empty string is 0.


Conjuntos de estudio relacionados

A&P Chapter 9 The Endocrine System

View Set

Chapter 8- Control, Change, and Entrepreneurship

View Set

chapter 3: sensation and perception

View Set

Business Information Systems - Excel 1-4

View Set

Maternal/Newborn Nursing content from Textbook of Basic Nursing, 11th Edition

View Set

Study Plan: Anxiety Disorders, Study Plan: The Etiology and Treatment of Mental Disorders, People and Terms: The Etiology and Treatment of Mental Disorders, Show What You Know: The Etiology and Treatment of Mental Disorders, Self-Check: Anxiety Disor...

View Set

Solar System Final (Mercury, Venus, Mars, Asteroids, Jupiter & Saturn, Uranus & Neptune, Comets, Exoplanets

View Set