Introduction to JavaScript Arrays
This article was AI-drafted and has not been reviewed yet. Spotted a mistake? Tell us.
Learn how to create and use arrays in JavaScript.
Introduction to JavaScript Arrays
Arrays are used to store a collection of values in a single variable. In this tutorial, we will cover the basics of JavaScript arrays.
Creating an Array
To create an array in JavaScript, you can use the [] syntax or the Array constructor. Here is an example of how to create an array:
let fruits = ['apple', 'banana', 'orange'];
Accessing Array Elements
To access an element in an array, you can use the index of the element. Here is an example of how to access an array element:
let fruits = ['apple', 'banana', 'orange'];
console.log(fruits[0]);
Array Methods
JavaScript arrays have several built-in methods, such as push, pop, shift, and unshift. Here is an example of how to use some of these methods:
let fruits = ['apple', 'banana', 'orange'];
fruits.push('grape');
console.log(fruits);
fruits.pop();
console.log(fruits);
Conclusion
In this tutorial, we covered the basics of JavaScript arrays. We learned how to create arrays, access array elements, and use array methods.
Ready for more? Optional paid resources that pick up where this lesson leaves off.
Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.
Project-based javascript courses if you want a structured paid path after the free lessons. Wait for a sale — prices drop often.
Browse on Udemy →Search Amazon for javascript books — check the publication year so the examples match current versions.
Search Amazon →