Array Elements | Position of Array Element | index value|JavaScript

As we know we can store multiple data(elements) in an array.
Every element of an array has position which is known as index value.

let arr = [10,20,30,40,50,60];
// every element has its index value

Note: Index value Starts with Zero (0) .
Count Index value increases as per the element present in it.

let arr = [10,20,30,40,50,60];
// here position of first element (10) is 0
// and it is repesented in array as follows
console.log(arr[0]); // 10
console.log(arr[1]); // 20
console.log(arr[2]); // 30
console.log(arr[3]); // 40
console.log(arr[4]); // 50
console.log(arr[5]); // 60

In short position of first element is found using arr[0]
And position of last element is found using arr[arr.length-1]

let arr = [10,20,30,40,50,60];
let firstELement = arr[0];
let lastElement = arr[arr.length-1];
console.log("First ELement",firstElement);  //10
console.log("Last Element",lastElement);   //60

Ganesh Patil | TA - Edyoda

3 Likes