Array Methods in JavaScript


Array methods in javascript- in this article, I am going to show you how to use array methods and properties with programming examples.

Array Properties and methods in JavaScript:

JavaScript considers an array as an object. An object is a collection of properties and methods. The length or size of an array represents the property. Methods of an object are use to access the data(read or modify data) from the object.

length property in JavaScript:

The length property in javaScript is used to find the length or size of an array. For example, to find the length of an array ‘abc’, the statement is written as;

The size of the array abc will be assigned to the variable ‘s’

For example, if an array is declared as;

The statement “document.write(arr.length);” will display 15 in the browser window.

Array Methods in JavaScript:

The most important and commonly used methods in JavaScript associated with array objects are as follows.

Concat method in javaScript:

The word concat stands for concatenate, which means combine. The concat method in javascript is used to combine two arrays. It creates new array and assigns the contents of two combine arrays to new created array.

General syntax of concat method in javaScript:

Where var1 and var2 are two arrays that you want to combine together. The combined data of two arrays will be assigned to new created array var3.

Example1: how to use concat method in javascript programming:

For example, to combine the contents of two arrays var1 and var2 into new created array var3, javascript code is given as follows:


methods in JavaScript

Join method in JavaScript:

join method in javascript combines all values of elements of an array into a string and returns a string.

General syntax of join method in javascript:

Where separator specifies the character that will be displayed between the contents of the elements of array. If separator is not specifies, then comma(,) will be displayed by default as a separator.

example2: how use join method in javascript:


methods in JavaScript

Reverse method in javascript:

reverse method in javascript is used to reverse the contents of elements in an array.

General syntax of reverse method in javascript:

Example3:  how to use reverse method in javascrpt:


methods in JavaScript

Sort method in javascript:

 sort method in javascript is used to sort the contents of an array.

General syntax of sort method in javascript:

Exmaple3: how to use sort method in javascript:


methods in JavaScript

toString method in javascript:

toString method in javascript is used to convert the content of an array into string. The data of different elements of an array are separated by commas.

General syntax toString method in javascript:

Example4: how to use toString method in javascript:


methods in JavaScript

Related Articles:

JavaScript Form validation: Checking Empty, Numeric, Alphabetic values

Date Objects in JavaScript Properties and Methods with Examples


Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button