feat(curriculum): Add interactive examples to What Are the Key Characteristics of JavaScript Arrays (#63279)

Co-authored-by: Ilenia <26656284+ilenia-magoni@users.noreply.github.com>
This commit is contained in:
Clarence Bakosi
2025-10-30 11:49:52 +01:00
committed by GitHub
parent de7ad9fa1c
commit 5d67399cad
@@ -5,7 +5,7 @@ challengeType: 19
dashedName: what-are-the-key-characteristics-of-javascript-arrays
---
# --description--
# --interactive--
An array in JavaScript is an ordered collection of values, each identified by a numeric index. The values in a JavaScript array can be of different data types, including numbers, strings, booleans, objects, and even other arrays.
@@ -19,21 +19,29 @@ In this example, we declare a variable `fruits` and assign it an array containin
One of the key characteristics of arrays is that they are zero-indexed, meaning that the first element in an array has an index of `0`, the second element has an index of `1`, and so on. You can access individual elements in an array using their index. For example:
:::interactive_editor
```js
let fruits = ["apple", "banana", "orange"];
console.log(fruits[0]); // "apple"
console.log(fruits[2]); // "orange"
```
:::
In this example, we use the index `0` to access the first element (`apple`) and the index `2` to access the third element (`orange`).
Arrays in JavaScript have a special `length` property that returns the number of elements in the array. You can access this property using the `length` keyword. For example:
:::interactive_editor
```js
let fruits = ["apple", "banana", "orange"];
console.log(fruits.length); // 3
```
:::
Another key characteristic of arrays in JavaScript is that they are dynamic, meaning that their size can change after they are created. You can add or remove elements from an array using various array methods, such as `push()`, `pop()`, `shift()`, `unshift()`, `splice()`, and more. These methods will be taught in upcoming lessons.
JavaScript arrays are versatile and useful when it comes to data storage inside your programs. Throughout this module, you'll get to see firsthand how working with arrays will help you efficiently manage and manipulate collections of data.