How to make the data equal to the first array

Tell us what’s happening:
Describe your issue in detail here.f
None of the hints work for me. I don’t now how to make the data equal to the first array. Can someone help?

Your code so far


//example
const myArray = [50, 60, 70];
var ourData = ourArray[0]; //equals 50

//setup
var myArray = [50, 60, 70];

//only change the code below this lin
var myData = myArray[0];
consle.log(myData)

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14324.72.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.91 Safari/537.36

Challenge: Access Array Data with Indexes

Link to the challenge:

Hmm, this isn’t in the starter code.

You’ve pasted a bunch of things in there that can’t go together.

Looking at the error,

SyntaxError: unknown: Identifier 'myArray' has already been declared. (6:4)

You can’t declare myArray twice!

This shouldn’t be there.


When you fix this, you get the error

ReferenceError: ourArray is not defined

so, you’ll need to remove that line as well.


Then you’ll get the error

ReferenceError: consle is not defined

so, you will need to fix that typo as well.


This is the problem with copy-pasting old solutions you find lying around. You end up with a mess in your code. You only need to add one line to the starter code to get this challenge to pass. You have that line buried among all the other stuff you put in your code.

1 Like

It needs to be equal to the first element in the array, not the whole array. The example in the challenge should be enough help for you to finish it.

Hey There
I hope this helps:
1- Arrays are index based:
myArray = [50,60,70]

  • That means that 50 is at index of 0, 60 is at index of 1, 70 is at index of 2
    2- Accessing elements of an array:
    If you want to access 50 for example, you need to:
  • reference the array by name (without let or const because it has already been declared) and then inside brackets specify which index you want… in this case 0.
    console.log(myArray[0]) → Should give you 50
    3- Accessing does nothing but “read” that info unless you store it somewhere:

const chooseTheName = myArray[index of the value you want]
4- Now, if you console.log(chooseTheName) it has the value of the index you asked for saved.

--------------- EXAMPLE:

const simpleArr = [1,2,3]
const getOne = simpleArr[0]
console.log(getOne)
const getTwo = simpleArr[1]
console.log(getTwo)
const getThree = simpleArr[2]
console.log(getThree)

Hope it helped =)
Good luck and keep pushing!

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