Arrays
let marks =[10,20,30,40,50,90];
const fruits =["orange","apple","banana","grapes"];
const mixed =[3,5,[6,"pushan"]];
const arr4 =new Array(23,144,"verma"); //new method to initialize array , just like java
console.log(arr4);
console.log(marks);
length of array
//changing value of array
marks[1]=200000;
console.log(marks);
indexof
console.log(marks.indexOf(30)); // present so gives index of array
console.log(marks.indexOf(1000000000000)); // not present in array so gives -1
Methods in Arrays
push -add to last
marks.push(70);
console.log(marks);
unshift -add to first
marks.unshift(100);
console.log(marks);
pop - removes element from last of array
marks.pop();
console.log(marks);
shift-it will remove elements from begin
marks.shift();
console.log(marks);
splice - it removes the elements from given indexes
marks.splice(1,3);
console.log(marks);
*reverse - it reverse the array *
marks.reverse();
console.log(marks);
concat-concat the array with another array
marks2=[100,200,300,400,500];
marks=marks.concat(marks2);
console.log(marks);
**All the properties are changing the whole array**
Top comments (0)