Files
Randell Dawson 1494a50123 fix(guide): restructure curriculum guide articles (#36501)
* fix: restructure certifications guide articles
* fix: added 3 dashes line before prob expl
* fix: added 3 dashes line before hints
* fix: added 3 dashes line before solutions
2019-07-24 13:29:27 +05:30

1.3 KiB

title
title
Use an Array to Store a Collection of Data

Use an Array to Store a Collection of Data

Problem Explanation

  • In JS, Arrays are one of the most commonly used data structure. Unlike other languages Arrays in JS can store different data types and can also change their size on runtime and hence are also referred as "Dynamic Arrays". They are also 0 indexed.

  • Arrays can be initialized in different ways:

    1. Array literals
    2. Array constructors
  • In this challenge we'll focus on Array literals. To initialize an array we simply do let arr = [];

  • We can add values to this array by accessing its index, example:

let arr = [];
arr[0] = "hello";
console.log(arr); // ["hello"]
  • We can also initialize the values in the array when we declare it, example:
let arr = [1, 2, 3, "John"];
  • In this challenge you need to create an array with at least 5 elements and at least one string, one number, and one boolean.

Solutions

Solution 1 (Click to Show/Hide) ```js let yourArray = ["a", 2, true, "c", null, { name: "john" }]; ```

Further reading about arrays at MDN.