Presentation is loading. Please wait.

Presentation is loading. Please wait.

Arrays “Array, I'm bound array, 'cross the wide Missouri.” ‒ Old Programmer’s Folk Song © Copyright 2014, Fred McClurg All Rights Reserved.

Similar presentations


Presentation on theme: "Arrays “Array, I'm bound array, 'cross the wide Missouri.” ‒ Old Programmer’s Folk Song © Copyright 2014, Fred McClurg All Rights Reserved."— Presentation transcript:

1 Arrays “Array, I'm bound array, 'cross the wide Missouri.” ‒ Old Programmer’s Folk Song © Copyright 2014, Fred McClurg All Rights Reserved

2 Array Declared What is an array? Set of values that are accessed by a variable name and a numeric index. Used to preserve a list order. Examples: // declare array var emptyArray = []; // square brackets // print array console.log( emptyArray ); 2 arrayDeclare.html

3 Element Initialization How do you initialize each element of an array? An array can be initialized element by element by referencing the index value. Examples: var dwarfs = []; // initialize empty array dwarfs[0] = "Doc"; dwarfs[1] = "Dopey"; dwarfs[2] = "Bashful"; dwarfs[3] = "Grumpy"; dwarfs[4] = "Sneezy"; dwarfs[5] = "Sleepy"; dwarfs[6] = "Happy"; dwarfs.length; // 7 dwarfs[ dwarfs.length - 1 ]; // "Happy" 3 elementInit.html

4 Array Initialization How do you initialize an entire array? All the elements in an array can be initialized in a single statement during declaration. Examples: // declare and initialize array var dow = [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ]; console.log( dow[0] ); // "Sun" console.log( dow.length ); // 7 4 arrayInit.html

5 Multiple Element Types What can you store in an array? An array can contain multiple data types. Examples: var mixedType = [ 1, 2, 3, // integers "a", "b", "c", // strings true, false // booleans ]; console.log( mixedType ); 5 multiElemTypes.html


Download ppt "Arrays “Array, I'm bound array, 'cross the wide Missouri.” ‒ Old Programmer’s Folk Song © Copyright 2014, Fred McClurg All Rights Reserved."

Similar presentations


Ads by Google