Posts

Showing posts with the label Array method

how to insert an element into an array in javascript

Image
 How to insert an element into an array in javascript To create an array in javascript you have to use a variable to store the array data // first use a variable to  store array value var Arr; // This will intialize the array value // Now create the array obj with the help of new Keyword Arr = new Array(); // Now add the elements in the Array using the predefined array method // first to add element we will use the push() method //Syntax: push() // Inorder to add elements you will have to follow these steps: Arr.push(); // Now you can add elements in the array with .push() method //Just mention the element you want to insert //for example Arr.push('apple'); //Now this adds the apple into the array  // How will the array look like  //Array[apple]  //length = 1 // index of apple would be 0 // You can add multiple elements on the go or Add single element one by one as metioned Above // How to add elements on one Go or in one line Arr.push('kiwi',grapes','orange...