Creating and Accessing arrays

let arr=[1,2,3,4,5,6,7,8,9,10];
console.log(arr[0]);
console.log(arr[1]);
console.log(arr[20]);

let names=['Vignesh','Eswar','Fakrudddin'];
console.log(names[0]);
console.log(names[1]);
console.log(names[3]);

Iteration in Arrays

let names=['Vignesh','Eswar','Fakrudddin'];
console.log(names);

// For loop
for(let i=0;i<names.length;i++){
    console.log(names[i]);
}

// For of loop
for(let name of names){
    console.log(name);
}
 
// For each loop
names.forEach(function(name){
    console.log(name);
});

Insertion

Push

array.push(item1,item2,item3,...) at the end of array

Unshift

array.unshift(item1,item2,item3,...) at the front of array

Splice Method:

array.splice(startIndex,deleteCount,itemsToInsert) at startIndex

let names=['Vignesh','Eswar','Fakrudddin'];
console.log(names);

// Insert at beginning of array - unshift()
names.unshift('Pavan','Sumanth');
console.log(names);
// Insert at end of array - push()
names.push('Dhanush','Susruth');
console.log(names);
// Insert at specific index - splice()
names.splice(2,0,'Thrinath');
console.log(names);