Basic JavaScript - Nest one Array within Another Array

Tell us what’s happening:
Describe your issue in detail here.

Your code so far What’s the purpose of a nested array if you could just add as many values you want in just a single array?

// Only change code below this line
const myArray = [["I am", 24], ["my wife is," 21]];

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Basic JavaScript - Nest one Array within Another Array

Link to the challenge:

You can use the nested arrays to group the data. You do not see it used very often but the nested arrays might be considered to be tuples, so it can be seen as an array of tuples.

JS doesn’t have tuples and you really do not need them. An array of objects or a Map is most likely a better choice.

Not sure I can think of a good example, to be honest.

const users = [
  ["John", 'red'],
  ["Jill", 'green'],
  ["Bill", 'blue'],
  ["Mary", 'orange']

document.documentElement.innerHTML = users
  .map((user) => `<h2 style="color: ${user[1]}">${user[0]}</h2>`)

Netflix’s home page is a list of lists of movies. Structurally the data might look something like this (a nested array):

    { title: 'Movie Title', ... },
    { title: 'Different Movie Title', ... },
    { title: 'Yet Another Movie', ... },
    { title: 'Your Favorite Movie', ... },

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.