UNPKG

javascripting

Version:

Learn JavaScript by adventuring around in the terminal.

48 lines (29 loc) 840 B
Array elements can be accessed through index number. Index number starts from zero to array's property length minus one. Here is an example: ```js var pets = ['cat', 'dog', 'rat']; console.log(pets[0]); ``` The above code will print the first element of `pets` array - string `cat`. Array elements must be accessed through only using bracket notation. Dot notation is invalid. Valid notation: ```js console.log(pets[0]); ``` Invalid notation: ``` console.log(pets.1); ``` ## The challenge: Create a file named `accessing-array-values.js`. In that file, define array `food` : ```js var food = ['apple', 'pizza', 'pear']; ``` Use `console.log()` to print the `second` value of array to the terminal. Check to see if your program is correct by running this command: ```bash javascripting verify accessing-array-values.js ```