Introductions to Arrays in JavaScript

 //Arrays are variables which can hold more than one value

let marks_class_12 = [91, 62, 33, 84, false, "Not Present"];
console.log(marks_class_12);
console.log(marks_class_12[0]);
console.log(marks_class_12[1]);
console.log(marks_class_12[2]);
console.log(marks_class_12[3]);
console.log(marks_class_12[4]);
console.log(marks_class_12[5]);
console.log(marks_class_12[6]); //Will be undefined because index 6 does not exist
console.log("The Length of marks_class_12 is :", marks_class_12.length);
marks_class_12[6] = 98; //Adding a new value to an Array
marks_class_12[0] = 100; // Changing the value of an Array
console.log(marks_class_12);
console.log("The Length of marks_class_12 is :", marks_class_12.length);

//In JavaScript, arrays are objects. The typeof operator on arrays returns object
console.log(typeof marks_class_12);

//Arrays can hold many values under a single name
for (let i = 0; i < marks_class_12.length; i++) {
    console.log(marks_class_12[i]);
}


OUTPUT :
[ 91, 62, 33, 84, false, 'Not Present' ] 91 62 33 84 false Not Present undefined The Length of marks_class_12 is : 6 [ 100, 62, 33, 84, false, 'Not Present', 98 ] The Length of marks_class_12 is : 7 object 100 62 33 84 false Not Present 98

Comments

Popular posts from this blog

Generators tutorial in Advance JavaScript

Document Object Module DOM querySelector and querySelectorAll tutorial in JavaScript

Find Even and Odd Numbers with Loops tutorial in JavaScript