Home / Web Development / Javascript / JavaScript Arrays

JavaScript Arrays

Hi all,
Today we discuss one useful topic related to Javascript Array. An array is an object. This is mainly used to store a collection of items. Arrays become really very useful, you need to store large amounts of data of the same type.




You can access the items in an array by referring to its indexnumber and the index of the first element of any array is zero.

Creating an Array

You can create an array in JavaScript as given below.

Here, you are initializing your array as and when it is created with values “Jose”, “Varghese” and “Thomas”. The index of “Jose”, “Varghese” and “Thomas” is 0, 1 and 2 respectively. If you want to add more elements to the students array, you can do it like this:




You can also create an array using Array constructor like this:

OR

Properties and Methods

The Array object has many methods and properties which help developers to handle arrays easily and efficiently.
You can get the value of a property by specifying arrayname.property and the output of a method by specifying arrayname.method().




  • length property: to know the number of elements in an array, you can use the length property.
  • prototype property: to add new properties and methods, you can use the prototype property.
  • reverse method : reverse the order of items in an array using reverse method.
  • sort method : sort the items in an array using sort method.



  • pop method : remove the last item of an array using pop method.
  • shift method : remove the first item of an array using shift method.

If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

Loading Facebook Comments ...
Social Media Auto Publish Powered By : XYZScripts.com