0
0
Javascriptprogramming~10 mins

Array creation in Javascript - Mini Project: Build & Apply

Choose your learning style9 modes available
Array creation
πŸ“– Scenario: You are helping a small shop owner keep track of the products they sell. The owner wants to list the products in an array so they can easily add more later.
🎯 Goal: Create an array of product names and display it.
πŸ“‹ What You'll Learn
Create an array called products with the exact items: "Apples", "Bananas", "Carrots"
Create a variable called newProduct and set it to "Dates"
Add newProduct to the products array using the push method
Print the products array to the console
πŸ’‘ Why This Matters
🌍 Real World
Arrays help store lists of items like products, names, or tasks in many apps and websites.
πŸ’Ό Career
Knowing how to create and manage arrays is a basic skill for any programming job involving data handling.
Progress0 / 4 steps
1
Create the initial array
Create an array called products with these exact items: "Apples", "Bananas", "Carrots"
Javascript
Need a hint?

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

2
Add a new product variable
Create a variable called newProduct and set it to the string "Dates"
Javascript
Need a hint?

Use const newProduct = "Dates"; to create the variable.

3
Add the new product to the array
Use the push method on the products array to add the newProduct variable
Javascript
Need a hint?

Use products.push(newProduct); to add the item.

4
Display the final array
Print the products array to the console using console.log
Javascript
Need a hint?

Use console.log(products); to show the array.