Skip to main content

Command Palette

Search for a command to run...

Javascript Arrays

Arrays In Javascript

Updated
•2 min read•View as Markdown
Javascript Arrays
A

Full-Stack Web Developer

JavaScript Array

JavaScript array is an object that represent a collection of similar type of elements.

There are 3 ways to construct array in JavaScript.

  • JavaScript Array Literal

    var arrayname=[value1, value2....valueN];
    
  • JavaScript Array Directly

    var arrayname=new Array();
    

Here, new keyword is used to create instance of array.

  • JavaScript array constructor

    Here, you need to create instance of array by passing arguments in constructor so that we don't have to provide value explicitly.

EXAMPLE

 <script>
   var emp = new Array("Shakti", "Amit", "Subo",);
      for ( i=0 i< emp .length; i++){
        document write (emp [ i ] +"<br>")
         }
       </script>

Output

Shakti

Amit

Subo

JavaScript Array Methods

Concat()

It returns a new array object that contains two or more merged arrays.

CopyWithin()

It copies the part of the given array with its own element and returns the modified array.

entries()

It creates an iterator object and a loop that iterates over each key/value pair.

every()

It determines Whether all the elements of an array are satisfying the provided function conditions.

flat()

It creates a new array carrying sub-array elements concatenates recursively till the specified depth.

flatMap()

It maps all array elements via mapping functions than flattens the result into a new array.

fill()

It fills elements into an array with static values.

forEach()

It invokes the provided function once for each element of an array.

includes()

It checks weather the given array contains the specified element.

isArray()

It tests if the passed value is an array.

join()

It joins the elements of an array as a string.

push()

It adds one or more elements to the end of an array.