0
0
Javascriptprogramming~15 mins

Accessing array elements in Javascript - Mini Project: Build & Apply

Choose your learning style9 modes available
Accessing array elements
πŸ“– Scenario: You are working on a simple shopping list app. You need to store the list of items and then access specific items by their position in the list.
🎯 Goal: Learn how to create an array and access its elements by index in JavaScript.
πŸ“‹ What You'll Learn
Create an array with exact items
Create a variable to hold the index to access
Access the array element using the index variable
Print the accessed element
πŸ’‘ Why This Matters
🌍 Real World
Arrays are used everywhere to store lists of things like shopping items, tasks, or names. Accessing elements by position helps you get or change specific items.
πŸ’Ό Career
Knowing how to work with arrays and access their elements is a basic skill for any programming job, especially in web development and data handling.
Progress0 / 4 steps
1
Create the shopping list array
Create an array called shoppingList with these exact items in order: "milk", "bread", "eggs", "butter", "cheese".

Javascript
Need a hint?

Use square brackets [] to create an array and separate items with commas.

2
Create an index variable
Create a variable called index and set it to 2 to represent the position of the item you want to access in the shoppingList array.
Javascript
Need a hint?

Use const to create a variable and assign the number 2 to it.

3
Access the array element using the index
Create a variable called item and set it to the element in shoppingList at position index.
Javascript
Need a hint?

Use square brackets with the variable index to get the element from the array.

4
Print the accessed item
Write a console.log statement to print the value of the variable item.
Javascript
Need a hint?

Use console.log(item); to show the item in the console.