string methods javascript
snippet in javascript

string methods javascript

user9195

// ... : Variadic (As many args as memory can handle) 
// [arg] : Optional Argument

charAt(index) // Returns the character at the specified index (position)
charCodeAt(index) // Returns the Unicode of the character at the specified index
concat(str1,[...]) // Joins two or more strings, and returns a new joined strings
endsWith(searchVal,[length]) // Checks whether a string ends with specified string/characters
fromCharCode(n1,[...]) // Converts Unicode values to characters
includes(searchVal,[start]) // Checks whether a string contains the specified string/characters
indexOf(searchVal,[start]) // Returns the position of the first found occurrence of a specified value in a string
lastIndexOf(searchVal,[start]) // Returns the position of the last found occurrence of a specified value in a string
localeCompare(str) // Compares two strings in the current locale
match(regex) // Searches a string for a match against a regular expression, and returns the matches
repeat(count) // Returns a new string with a specified number of copies of an existing string
replace(searchVal,newVal) // Searches a string for a specified value, or a regular expression, and returns a new string where the specified values are replaced
search(searchVal) // Searches a string for a specified value, or regular expression, and returns the position of the match
slice(start,[end]) // Extracts a part of a string and returns a new string
split([separator],[limit]) // Splits a string into an array of substrings
startsWith(searchVal,[start]) // Checks whether a string begins with specified characters
substr(start,[length]) // Extracts the characters from a string, beginning at a specified start position, and through the specified number of character
substring(start,[end]) // Extracts the characters from a string, between two specified indices
toLocaleLowerCase() // Converts a string to lowercase letters, according to the host's locale
toLocaleUpperCase() // Converts a string to uppercase letters, according to the host's locale
toLowerCase() // Converts a string to lowercase letters
toString() // Returns the value of a String object
toUpperCase() // Converts a string to uppercase letters
trim() // Removes whitespace from both ends of a string
valueOf() // Returns the primitive value of a String object

js string methods

user9532

JS String Methods:
charAt()
Returns a character at a specified position inside a string
charCodeAt()
Gives you the unicode of character at that position
concat()
Concatenates (joins) two or more strings into one
fromCharCode()
Returns a string created from the specified sequence of UTF-16 code units
indexOf()
Provides the position of the first occurrence of a specified text within a string
lastIndexOf()
Same as indexOf() but with the last occurrence, searching backwards
match()
Retrieves the matches of a string against a search pattern
replace()
Find and replace specific text in a string
search()
Executes a search for a matching text and returns its position
slice()
Extracts a section of a string and returns it as a new string
split()
Splits a string object into an array of strings at a specified position
substr()
Similar to slice() but extracts a substring depended on a specified number of characters
substring()
Also similar to slice() but can’t accept negative indices
toLowerCase()
Convert strings to lowercase
toUpperCase()
Convert strings to uppercase
valueOf()
Returns the primitive value (that has no properties or methods) of a string object

js string methods

user6974

// String methods:
'hello'.toUpperCase(); // "HELLO";
'LOL'.toLowerCase(); // "lol"
'    omg  '.trim(); // "omg"

// String methods with arguments:
// ==============================

//indexOf returns the index where the character is found (or -1 if not found)
'spider'.indexOf('i'); //2
'vesuvius'.indexOf('u'); //3 - only returns FIRST matching index
'cactus'.indexOf('z'); //-1 not found

// slice - returns a "slice" of a string
"pancake".slice(3); //"cake" - slice from index 3 onwards
"pancake".slice(0, 3); //"pan" - slice from index 0 up to index 3

// replace - returns a new string, with the FIRST match replaced
"pump".replace("p", "b"); //"bump" - only replaces first "p"

// String Template Literals
// Use backtick characters, NOT SINGLE QUOTES!

straforma in stringa js

user525

var x = new String("Una nuova stringa");