Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Introduction to Arrays | Advanced Primitives and Reference Types
Quizzes & Challenges
Quizzes
Challenges
/
JavaScript Data Types Foundations

bookIntroduction to Arrays

Arrays are a powerful way to organize and manage collections of data in JavaScript. You will encounter arrays in many real-world situations, such as storing the items in a shopping cart, keeping track of a list of tasks, or managing user input in a form. Arrays allow you to group related values together, making it easier to process and manipulate them as a unit.

12345678
// Create an array of shopping cart items const shoppingCart = ["apple", "banana", "orange"]; // Access the first item in the array console.log(shoppingCart[0]); // Output: "apple" // Access the second item in the array console.log(shoppingCart[1]); // Output: "banana"
copy

Arrays use numeric indexing, starting from 0. This means the first element is at index 0, the second at index 1, and so on. You can retrieve any item by its index. Arrays also have a length property, which tells you how many elements are in the array. For example, if your array has three items, its length will be 3. This property is especially useful when you need to loop through an array or check if it contains any elements.

question mark

Which statement about JavaScript arrays is correct?

Select the correct answer

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 3. Kapittel 3

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

Awesome!

Completion rate improved to 6.25

bookIntroduction to Arrays

Sveip for å vise menyen

Arrays are a powerful way to organize and manage collections of data in JavaScript. You will encounter arrays in many real-world situations, such as storing the items in a shopping cart, keeping track of a list of tasks, or managing user input in a form. Arrays allow you to group related values together, making it easier to process and manipulate them as a unit.

12345678
// Create an array of shopping cart items const shoppingCart = ["apple", "banana", "orange"]; // Access the first item in the array console.log(shoppingCart[0]); // Output: "apple" // Access the second item in the array console.log(shoppingCart[1]); // Output: "banana"
copy

Arrays use numeric indexing, starting from 0. This means the first element is at index 0, the second at index 1, and so on. You can retrieve any item by its index. Arrays also have a length property, which tells you how many elements are in the array. For example, if your array has three items, its length will be 3. This property is especially useful when you need to loop through an array or check if it contains any elements.

question mark

Which statement about JavaScript arrays is correct?

Select the correct answer

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 3. Kapittel 3
some-alt