Skip to content

Latest commit

 

History

History
26 lines (20 loc) · 642 Bytes

File metadata and controls

26 lines (20 loc) · 642 Bytes

You can get a single value out of an array using bracket notation.

$ node
> var ingredients = ["Flour", "Water", "Salt"];
undefined
> ingredients[0]
Flour
> ingredients[1]
Water
> ingredients.length
3

Did you notice how we use [0] to get the first value? In programming we count starting at zero.

The number inside of the brackets is called an index. Index just means the position of the item within the array.

You can also set a value using bracket notation and an assignment operator (=).

var scores = [80, 41, 47];

scores[2] = 29; // Change the last score
scores[3] = 51; // Add a new score