Quick Reference
This is a quick reference list of JavaScript string methods and properties with examples of how they are used.
- JavaScript – String charAt() MethodThe String charAt() method returns the character at a specified position in a string.
- JavaScript – String charCodeAt() MethodThe String charAt() method returns the Unicode (UTF-16) of the character at a specified position in a string.
- JavaScript – String codePointAt() MethodThe String codePointAt() method returns the Unicode of the character at a specified position in a string.
- JavaScript – String concat() MethodThe String concat() method joins two or more strings, returning a new string, without changing the existing strings.
- JavaScript – String constructor PropertyThe String constructor property returns the function that created the String prototype.
- JavaScript – String endsWith() MethodThe String endsWith() method returns true if a string ends with a specified string, if not, it returns false. The method is case sensitive.
- JavaScript – String.fromCharCode() MethodThe String.fromCharCode() method converts Unicode values to characters.
- JavaScript – String includes() MethodThe String includes() method returns “true” if a string contains a specified string, if not, it returns “false”. The method is case sensitive.
- JavaScript – String indexOf() MethodThe String indexOf() method returns the position of the first occurrence of a value in a string, and returns -1 if the value is not found.
- JavaScript – String lastIndexOf() MethodThe String lastIndexOf() method returns the position of the last occurrence, searching from the end to the beginning, of a specified value in a string.
- JavaScript – String length PropertyThe String length property returns the length of a string. An empty string will return 0.
- JavaScript – String localeCompare() MethodThe String localeCompare() method compares two strings in the current locale, and returns their sort order -1, 1, or 0 (before, after, equal).
- JavaScript – String match() MethodThe String match() method matches a string against a regular expression, returning an array with the matches or null if no match is found.
- JavaScript – String prototype PropertyThe String prototype property allows the addition of new properties and methods to strings.
- JavaScript – String repeat() MethodThe String repeat() method returns a new string with a number of copies of an existing string, without changing the original string.
- JavaScript – String replace() MethodThe String replace() method searches a string for a value or a regular expression, and returns a new string with the values replaced.
- JavaScript – String search() MethodThe String search() method matches a string against a regular expression, returning the position of the first match or -1 if no match is found.
- JavaScript – String slice() MethodThe String slice() method extracts a part of a string, returning the extracted part as a new string, without changing the original string.
- JavaScript – String split() MethodThe String split() method splits a string into an array of substrings, and returns a new array, without changing the original string.
- JavaScript – String startsWith() MethodThe String startsWith() method returns “true” if a string starts with a specified string, if not, it returns “false”.
- JavaScript – String substr() MethodThe String substr() method extracts characters from a string starting at a specified position, returning the extracted part as a new string.
- JavaScript – String substring() MethodThe String substring() method extracts characters from a string, between two positions, returning a substring, while not changing the original string.
- JavaScript – String toLocaleLowerCase() MethodThe String toLocaleLowerCase() method converts a string to lowercase letters, using the current locale, without changing the original string.
- JavaScript – String toLocaleUpperCase() MethodThe String toLocaleUpperCase() method converts a string to uppercase letters, using the current locale, without changing the original string.
- JavaScript – String toLowerCase() MethodThe String toLowerCase() method converts a string to lowercase letters, without changing the original string.
- JavaScript – String toString() MethodThe String toString() method returns a string object as a string, without changing the original string.
- JavaScript – String toUpperCase() MethodThe String toUpperCase() method converts a string to uppercase letters, without changing the original string.
- JavaScript – String trim() MethodThe String trim() method removes whitespace from both sides of a string, without changing the original string.
- JavaScript – String trimEnd() MethodThe String trimEnd() method removes whitespace from the end of a string, without changing the original string.
- JavaScript – String trimStart() MethodThe String trimStart() method removes whitespace from the beginning of a string, without changing the original string.
- JavaScript – String valueOf() MethodThe String valueOf() method returns the primitive value of a string, without changing the original string.
JavaScript Notes:
- When using JavaScript, single or double quotation marks are acceptable and work identically to one another; choose whichever you prefer, and stay consistent
- JavaScript is a case-sensitive language; firstName is NOT the same as firstname
- Arrays count starting from zero NOT one; so item 1 is position [0], item 2 is position [1], and item 3 is position [2] … and so on
- JavaScript variables must begin with a letter, $, or _
- JavaScript variables are case sensitive (x is not the same as X)
We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.