Pilcrow Records

Scripter Javascript Tutorial

javascriptmusiclogicscripterbookexcerpttutorial

43 Get Data from an Array

In arrays, each data value is sequentially numbered with an index starting at 0, similar to an address. So, if an array has 7 elements, then the first element is at index 0 and the last element is at index 6. Understanding that the count begins with 0 is important for looping through values.

var scale = ["do", "re", "mi", "fa", "so", "la", "ti"];
var d1 = scale[0]; // "do"
var mi = scale[2]; // "mi"
var ti = scale[6]; // "ti"
var d2 = scale[7]; // undefined; out of bounds

In the above example: