Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Challenge: Access Array Elements | Mastering JavaScript Arrays
JavaScript Data Structures

bookChallenge: Access Array Elements

Task

  1. Create an array called stars with the following star names:
    • "Sirius";
    • "Alpha Centauri";
    • "Betelgeuse";
    • "Polaris".
  2. Log individual star names using different indices (0, 1, 2, and 3) using console.log
123456
const stars = ___; console.log("First element:", ___); // Output: Sirius console.log("Second element:", ___); // Output: Alpha Centauri console.log("Third element:", ___); // Output: Betelgeuse console.log("Forth element:", ___); // Output: Polaris
copy

Expected output:

First element: Sirius
Second element: Alpha Centauri
Third element: Betelgeuse
Forth element: Polaris
  1. Use square brackets [] to create an array.
  2. Separate each element with the comma ,.
  3. Use console.log() to log the value of the array element at the specified index.
123456
const stars = ["Sirius", "Alpha Centauri", "Betelgeuse", "Polaris"]; console.log("First element:", stars[0]); // Output: Sirius console.log("Second element:", stars[1]); // Output: Alpha Centauri console.log("Third element:", stars[2]); // Output: Betelgeuse console.log("Forth element:", stars[3]); // Output: Polaris
copy

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 4. Розділ 2

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

bookChallenge: Access Array Elements

Task

  1. Create an array called stars with the following star names:
    • "Sirius";
    • "Alpha Centauri";
    • "Betelgeuse";
    • "Polaris".
  2. Log individual star names using different indices (0, 1, 2, and 3) using console.log
123456
const stars = ___; console.log("First element:", ___); // Output: Sirius console.log("Second element:", ___); // Output: Alpha Centauri console.log("Third element:", ___); // Output: Betelgeuse console.log("Forth element:", ___); // Output: Polaris
copy

Expected output:

First element: Sirius
Second element: Alpha Centauri
Third element: Betelgeuse
Forth element: Polaris
  1. Use square brackets [] to create an array.
  2. Separate each element with the comma ,.
  3. Use console.log() to log the value of the array element at the specified index.
123456
const stars = ["Sirius", "Alpha Centauri", "Betelgeuse", "Polaris"]; console.log("First element:", stars[0]); // Output: Sirius console.log("Second element:", stars[1]); // Output: Alpha Centauri console.log("Third element:", stars[2]); // Output: Betelgeuse console.log("Forth element:", stars[3]); // Output: Polaris
copy

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 4. Розділ 2
some-alt