What is array ?
used to store multiple values under same variable. eg.
const fruits = ["apple","banana","orange"];
Task - Create any 5 arrays as fast as possible.
There are two ways to create an empty array
const fruits = new Array();
const numbers = [];
Index in array
const fruits = ["apple","banana","orange"];
console.log(fruits[0]);
Task - Create an array of 15 students in a class. and then print the student of index 3,8,12,14 each along with template string - Congratulations, {name}. You are selected for the competition. (Dont use loop here as we are learning index).
Replacing elements with index
const fruits = ["apple","banana","orange"];
fruits[1] = "mango";
console.log(fruits);
Task - Create an array of 10 items in a shop of Newroad. Then replace the 3rd , 7th and 10th element with the item you wish. (note - replacing array[3] is not 3rd item, its 4th item.)
Adding element with index - not recommended because it create loop holes
const fruits = ["apple","banana","orange"];
fruits[5] = "mango";
console.log(fruits);
Finding length of string - array.length
note - array can have a trailing comma because it makes us easier to insert and remove items.