Introduction:

[arrays] are a list of variables. They are stored in square brackets, but can be created using new Array() round brackets.


myArray = ["one", "two", 3, 4, true, "true", false, "false"];

let myNewArray = new Array(1, 2, "three", "four");

  1. Declare (create) an array
  2. let x = [];

    Empty [array]

    let y = ["No", "longer", "empty"];

    Filled [array]


  3. Create an array from a string
  4. Method 1

    Method 2


  5. Transform an array into a string
  6. myArray.toString();

    Converts an [array] into a "string"

    myArray.join(separator);

    Converts an [array] into a "string"

  7. Retrieving Information
  8. myArray[3];

    myNewArray[3];

    Get value at position #3

    Get index of [array] value

    myArray.valueOf();

    Get values of [array]

    typeof(myArray[#]);

    Get data types of values in [array]

    Array.isArray(myArray);

    Determines if [array] or not. Returns boolean

    myArray.entries();

    Iterate through [array] and return key/value

    myArray.forEach(item, index);

    Iterate through [array] and return key/value

    myArray.keys();

    Iterate through [array] and return keys

    myArray.constructor;

    Returns constructor function for an object, thus tells whether something is a Number, a "string" or an [array]

    myArray.length;

    Returns the number of elements in an [array]

    myArray.indexOf(item, (start));

    Returns the index of elements in an [array]

    myArray.lastIndexOf(item, (start));

    Returns the last index of elements in an [array]

    myArray.includes(item, (start));

    Checks if an [array] contains a specific value. Returns a boolean