Javascript Array Methods – Tutorials & Code Examples

Javascript Array Methods – Tutorials & Code Examples. In this tutorial, we are going to learn about javascript array methods with code example.

Summary of topics which we cover in this tutorial.

  • What is an Array?
  • The Syntax of array declaration in Javascript.
  • Javascript array methods.

What is an Array?

Let’s first consider a situation where we have a list of items and we need to store them in a single variable. It could look like this:

Let’s assume our list has more than 500 items. Are we going to declare 500 variables? To handle such type of situation every programming language provides a data structure called array.

An array is a variable which holds multiple values of same types. It is an ideal choice for storing the list of values in a single variable.

For example –

How to Declare an Array in Javascript

There are multiple ways through which we can declare an array in Javascript.

i) Declare an array in Javascript using Array constructor.

We can define the above statement in a single line.

 

2. Declare an array in Javascript using literal notation

For simplicity, readability and execution speed array declaration using javascript literal notation is preferred.

 

Javascript Array Methods

How to check if a variable/object is an Array in Javascript

In javascript, Array.isArray() method is used to check whether a variable/object is an array or not.  Array.isArray() method returns true if an object is an array otherwise false.

How to get current date and time in javascript

Find Length of an Array in Javascript using Array Length Property

Javascript array length property returns the length of an array.

Append New Values at the end of an Array – Javascript Push() Method

Javascript array push() method is used to append one or more values at the end of an array.

Append Values at the Beginning of an Array using Javascript unshift() Method

Javascript unshift() method is used to append values at the beginning of an array.

Remove Last Element of an Array in Javascript using pop() Method

Javascript pop() method is used to remove last element of an array.

Remove First Element of an Array in Javascript using shift() Method

Javascript shift() method is used to remove first element of an array.

How to Combine Two or More Arrays in Javascript using concat() Method

Javascript concat() method is used to combine two or more arrays.

Convert an Array into String in Javascript using toString() Method

Javascript toString() method is used to convert an array into string.

We can also convert an array to string using join() method.

How to validate date format in Javascript

Tagged , . Bookmark the permalink.

About WebRewrite

I am technology lover who loves to keep updated with latest technology. My interest field is Web Development.