Arrays In JavaScript

Arrays In JavaScript

Arrays In Javascript

  1. Introduction to Array
  2. Creating an Array in Javascript
  3. Creating an Array with only Zeros/Only One
  4. Adding Elements in the Array
    1. Adding Elements to the start of the Array
    2. Adding elements to the end of the Array
  5. Removing Elements From the Array
    1. Removing Elements from the start
    2. Removing Elements from the rear
  6. Accessing the Elements in the Array
    1. Positive and Negative Indexing
    2. Using Indexof to find the index of the element
  7. Finding the length of the Array
  8. Iterating through elements of the Array
  9. Checking the type of Array
  10. Slicing And Splicing the Array
  11. Sorting an Array
  12. Checking if the Array Contains A particular value


  1. Introduction to Array: An array is a collection of data which may or may not be of the same data type

  2. Creating an Array in Javascript There are two ways in which we can create arrays in JavaScript. The most easy and mostly used way of creating a JavaScript array is

Capture.JPG

  1. Creating an Array with only Zeros / Ones

Capture2.JPG

4.Adding Elements in an Array Elements can be added in two ways one at the start and second at the end of the Array

  1. Adding elements at the start of the array

Capture4.JPG

2.Adding Elements at the end of the Array

Capture3.JPG

  1. Removing Elements from the Array Elements in array can be removed from the start or from the rear
    1. Removing elements from the Start

Capture9.JPG

start index is included and end index is excluded

  1. Removing from the rear

Capture10.JPG

  1. Accessing Elements using Index: JavaScript Arrays are 0-based indexes.This implies the starting index is 0 They only support positive indexing.

Capture5.JPG

If we try to use negative indexing to access the elements then we will get the output as undefined

Using indexof to find the index of the first occurrence of the element in the array

Capture14.JPG

  1. Finding the length of the Array

Capture6.JPG

  1. Iterating through all the elements of the Array

Capture7.JPG

  1. Checking the type of Array

Arrays in JavaScript are treated like Objects

Capture8.JPG

  1. Slicing and Splicing an array

    1.slicing

Capture11.JPG

2.Splicing

Capture12.JPG

  1. Sorting an Array By default sorting order is increasing

Capture13.JPG

12.Checking if the value Is present or not If the value is present then it will return true else will return false

Capture14JPG.JPG