JavaScript Arrays Explained: Everything You Need to Know


Array is special type of object that is used to store similar kind of in a single variable
We can create an array in two ways by using literal and also by the help of new Array
wee can use the difference between these two usage
int arr=[9] <script>
<script>
var Arr =[9];
document.writeln("The lenght of Arrr:"+Arr.length)
const ar=new Array(3)
document.writeln("The lenght of Ar:"+ar.length);
</script>
here we can see the difference the first one results as 1 but the second one gives the answer as 3 .
Modifying the elements in the array
let fruits =[‘apples’, ’banana’];
fruits[1]=’mango’;
we can give the mango to the index 1 and change the array.
Common array methods
fruits.push(‘cherry’);
it adds the fruits at the last
fruits.pop()
it removes the last element from the array.
fruits.unshift(‘cucmber’);
It adds the fruits at the begining
fruits.shift()
it remove the fruits from the beginning of the array.
Subscribe to my newsletter
Read articles from GAJULA VAISHNAVI directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

GAJULA VAISHNAVI
GAJULA VAISHNAVI
I am aspiring full stack java developer