02. Access by offset


#1

var languages = ["HTML", "CSS", "JavaScript", "Python", "Ruby"];
languages[3];

Is there something wrong in my code? even if i add console.log to it, it shows me error


#2

what's the error message and how did you add console.log ?


#3

Oops, try again. Looks like your code didn't log the third element of the languages array. Remember that array indexes start from 0.

this is the error i get


#4

Error:

Oops, try again. Looks like your code didn't log the third element of the languages array. Remember that array indexes start from 0.

Array indexes start from 0,It means the position of first element in the array is 0.so if we want to access the first element then we have to do like

languages[0] //prints HTML

not

languages[1] // prints CSS

now count the position of thrid element and print it :slight_smile:


#5

var languages = ["HTML", "CSS", "JavaScript", "Python", "Ruby"];
console.log(languages[2]);


#6

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