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`;


  1. Declaring (creating) strings:
  2. let myString = "This is my string"


  3. Creating strings from arrays:
  4. Method 1

    Method 2

  5. Transforming strings into arrays:
  6. Array.from(myLetter);

    Turns a "string" into an [array].

    myLetter.split();

    Splits according to the (argument). The split point is not included in the returned result.

  7. Retrieving Information:
  8. 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 #

  9. Manipulating:
  10. 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.