Back to Course

Introduction to JavaScript

0% Complete
0/0 Steps
  1. JavaScript: Basics
    9Topics
    |
    10 Quizzes
  2. JavaScript: Variables
    9Topics
    |
    10 Quizzes
  3. JavaScript: Conditional Statements
    10Topics
    |
    11 Quizzes
  4. JavaScript: Functions
    10Topics
    |
    11 Quizzes
  5. JavaScript: Scope
    6Topics
    |
    7 Quizzes
  6. JavaScript: Arrays
    11Topics
    |
    12 Quizzes
  7. JavaScript: Loops
    8Topics
    |
    9 Quizzes
  8. JavaScript: High Order Functions
    3Topics
    |
    4 Quizzes
  9. JavaScript: Iterators
    6Topics
    |
    6 Quizzes
Lesson 6, Topic 9
In Progress

JavaScript: Array Methods

Yasin Cakal 16 Nov 2021
Lesson Progress
0% Complete

There are many more array methods besides .push() and .pop(). The array documentation on the  Mozilla Developer Network (MDN) array documentation contains information on all of the array methods.
The arrays on which .pop() and .push() are called are mutated. When we don’t want to mutate the original array, we can use non-mutating array methods. Check MDN to learn about the behavior of the method you’re using.
Array methods available to JavaScript developers include: .join(),.slice(),.splice(),.shift(),.unshift(), and .concat(), among many others. Using these built-in methods makes it easier to perform some common array-related tasks.

Below, we will look at some methods that we haven’t yet learned. We’ll use these techniques to revise grocery array. As you go through the steps, you can look up what each method does in the MDN documentation!

const grocery = ['juice', 'bananas', 'coffee'];
console.log(grocery.slice(0, 2));
console.log(grocery);
const coffeeIndex = grocery.indexOf('coffee');
console.log(coffeeIndex);

//Output: [ 'juice', 'bananas' ]
          [ 'juice', 'bananas', 'coffee' ]
          2

Responses

Leave a Reply

%d bloggers like this: