Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Arrays | Section
JavaScript Essentials for React Native Development

bookArrays

Glissez pour afficher le menu

Arrays are ordered lists of values, stored in a single variable. You can think of an array as a collection of items, such as a list of fruit names, where each item has a specific position called an index. In JavaScript, array indexes start at 0, so the first element is at index 0, the second at index 1, and so on.

12345678910
// Creating an array const fruits = ["apple", "banana", "cherry"]; // Accessing elements by index console.log(fruits[0]); // "apple" console.log(fruits[2]); // "cherry" // Modifying values fruits[1] = "blueberry"; console.log(fruits); // ["apple", "blueberry", "cherry"]
copy

Accessing a value in an array is done by referencing its index inside square brackets. For example, fruits[0] gives you the first fruit in the array, while fruits[2] gives you the third. You can also change the value at a specific index by assigning a new value to it, like fruits[1] = "blueberry", which replaces the second fruit.

Arrays are commonly used to store lists of related data, such as items in a shopping cart, user names, or scores in a game. Their ability to hold multiple values and let you access or change them by index makes arrays a powerful tool for managing collections in your code.

question mark

Which statement about arrays in JavaScript is true?

Sélectionnez la réponse correcte

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 6

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

Section 1. Chapitre 6
some-alt