Back to Course

Introduction to JavaScript

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

JavaScript: Accessing Elements

Yasin Cakal 12 Nov 2021
Lesson Progress
0% Complete

Each array element has a numbered position known as its index. Individual items can be accessed using their index, which is similar to referencing an item in a list based on the item’s position.

In JavaScript, arrays are zero-indexed, which means that positions begin counting from 0 rather than 1. As a result, the first item in an array will be at index 0. Let’s look at how we can get to an array element:

const signalLight = ['Red', 'Green', 'Yellow'];
const listItem = signalLight[0];


In the previous code snippet:

  • The signalLight array has three elements.
  • To access the element, we use bracket notation, [ ], with the index following the name of the array.
  • signalLight[0] will access the element in the array signalLight at index 0. You can think of signalLight[0] as a memory location where the string Red is stored.
  • Individual characters in a string can also be accessed using bracket notation [ ] and the index.

For example, you could write:

const webName = 'CodeOfCode';

// Output: f

As f is the character at index 5, it will be displayed on the console.


Leave a Reply

%d bloggers like this: