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
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

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 3. Kapitel 3

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

Suggested prompts:

What are some common methods to add or remove items from an array?

How can I loop through all the items in an array?

Can you explain more about how array indexing works?

Awesome!

Completion rate improved to 6.25

bookIntroduction to Arrays

Stryg for at vise menuen

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

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 3. Kapitel 3
some-alt