Day 51
Did some work today on a cheat sheet. This is the array section.
#CodingPhase #TheCodingWay #365CodingPhaseChallenge
**********
// Array
var colors1 = []; //initialized array
var colors1 =['red', 'green', 'blue']; //initialized w/values
alert(colors1); //alert contains all values
alert(colors1[1]); //returns green
// Arrays are 0(zero) based.
// Three values are in positions 0, 1, and 2
// Alternate array declaration
var colors2 = new Array('grey', 'yellow', 'pink');
alert(colors2[2]); //returns pink
// Adding values to the array
colors2[3] = 'orange'; // works for known positions
// A better way to add values
colors2.push('teal'); // Called "dot" syntax
alert(colors2);
var numbers = [5,56,85,124,3,84,'Twenty']; // Values can be mixed
alert(numbers[0] + numbers[3]);
alert(numbers.length);
alert(numbers.sort());
alert(numbers.reverse());
// End Array
#CodingPhase #TheCodingWay #365CodingPhaseChallenge
**********
// Array
var colors1 = []; //initialized array
var colors1 =['red', 'green', 'blue']; //initialized w/values
alert(colors1); //alert contains all values
alert(colors1[1]); //returns green
// Arrays are 0(zero) based.
// Three values are in positions 0, 1, and 2
// Alternate array declaration
var colors2 = new Array('grey', 'yellow', 'pink');
alert(colors2[2]); //returns pink
// Adding values to the array
colors2[3] = 'orange'; // works for known positions
// A better way to add values
colors2.push('teal'); // Called "dot" syntax
alert(colors2);
var numbers = [5,56,85,124,3,84,'Twenty']; // Values can be mixed
alert(numbers[0] + numbers[3]);
alert(numbers.length);
alert(numbers.sort());
alert(numbers.reverse());
// End Array
Comments
Post a Comment