String Methods:
object.nameOfTheMethod(argument)
Javascript uses zero indexing!
For this page, all functions will use the following strings:
let myLetter = "I went into hospital on the 29th June, 2020.
A day later, I was operated on and had the colostomy bag attached to me.
On the 30th September I went back to hospital, where, happily, they removed the colostomy bag.
Now, I have just 4 months of preventive chemotherapy to do."
let imGlad = ` I'm glad I'm getting better!`;
let newImGlad = `I'm glad I'm getting better!`;
let im = `I'm`;
- Declaring (creating) strings:
- Creating strings from arrays:
- Transforming strings into arrays:
- Retrieving Information:
- Manipulating:
let myString = "This is my string"
myLetter.indexOf("o");
First index of "o"
myLetter.lastIndexOf("o");
Last index of "o"
myLetter.slice(#, #);
Return substring from position # until #-1
myLetter.charAt(#);
Returns character at position #
myLetter.charCodeAt(#);
Returns unicode value of character at position #
myLetter.concat(str1, str2);
Concatenates 2 strings
string.match(newString);
newString.match(string);
Finds out if there is a match within two strings
string.search(newString);
newString.search(string);
Returns the index of any EXACT match, or if none found, -1
myLetter.replace(/exisiting element/, "new element");
myLetter.replaceAll("existing element", "new element");
Replaces one or all instances of the element
myLetter.substr(50);
myLetter.substr(58, 50);
Returns substring from... to (to is optional)
myLetter = myLetter.substr(50, 50);
Changes original string using the same "from... to" effect.
myLetter.toLowerCase();
Converts all to lower case letters.
myLetter.toUpperCase();
Converts all to upper case letters.
myLetter.repeat(#);
Returns new substring repeated # of times.
myLetter.length;
Returns length of string. No () needed.