JavaScript Array unshift()

The JavaScript array unshift() method is used to add one or more elements at the starting index of the given array. Syntax: array.unshift (element1,element2,….) Parameters: element1,element2,… : The elements to be added in a given array. Returns: Original array with specific addition elements. Example: <!DOCTYPE html> <html> <body> <script> var a = [“GOLD”,”SILVER”,”DIAMOND”,”RUBY”,”PLATINUM”] var result=a.unshift(“BRONZE”); … Read more

JavaScript Array splice()

The JavaScript array splice() method is used to add/remove elements to/from the given array. Syntax: array.splice (start,delete,element1,element2,…) Parameters: start: It is a required parameter and represents the index from where the function starts to fetch the elements. delete: It is an optional parameter and represents the number of elements that have to be removed. element1,element2,… … Read more

JavaScript Array sort()

The JavaScript array sort() method is used to return the element of the given array in a sorted order. Syntax: array.sort(compareFunction) Parameters: compareFunction: It represents a function that provides the functionality of sort order. It is an optional parameter. Returns: An array with sorted elements. Example: <!DOCTYPE html> <html> <body> <script> var a = [“GOLD”,”SILVER”,”DIAMOND”,”RUBY”,”PLATINUM”] … Read more

JavaScript Array shift()

The JavaScript array shift() method is used to remove and return the first element of an array. Note: The length of the original array will be modified. Syntax: array. shift() Return: The first element of an array. Example: <!DOCTYPE html> <html> <body> <script> var a = [“GOLD”,”SILVER”,”DIAMOND”,”RUBY”,”PLATINUM”] var result=a.shift(); document.writeln(result + “<br>”); document.writeln(a); </script> </body> … Read more

JavaScript Array reverse()

The JavaScript array reverse() method is used to reverse the elements of the given array. Syntax: array.reverse() Return: Original array with elements in reverse order. Example: <!DOCTYPE html> <html> <body> <script> var a = [“GOLD”,”SILVER”,”DIAMOND”,”RUBY”,”PLATINUM”] var rev_a =a.reverse(); document.writeln(rev_a); </script> </body> </html>

JavaScript Array push()

The JavaScript array push() method is used to add one or more elements to the end of an array. Syntax: array.push (element1, element2….) Parameters: element1,element2… : Represents the elements to be added in an array. Returns: Original array with additional elements. Example: <!DOCTYPE html> <html> <head> </head> <body> <script> var a = [“GOLD”,”SILVER”,”DIAMOND”,”RUBY”,”PLATINUM”] a.push(“BRONZE”); document.writeln(a); … Read more

JavaScript Array pop()

The JavaScript array pop() method is used to remove and return the last element of an array. Syntax: array.pop() Syntax: It will return the last element of an array. Example: <!DOCTYPE html> <html> <head> </head> <body> <script> var a = [“GOLD”,”SILVER”,”DIAMOND”,”RUBY”,”PLATINUM”] document.writeln(a.pop()+”<br>”+”<br>”); document.writeln(a); </script> </body> </html>  

JavaScript Array map()

The JavaScript array map() method is used to call a particular function for each element of the array and returns the new array. Note: The original array will not be changed. It will return a new array. Syntax: array.map (callback(currentvalue,index,arr),thisArg) Parameters: callback: It represents the method to test the condition. It is required. currentValue: It … Read more

JavaScript Array lastIndexOf()

The JavaScript array lastIndexOf() method is used to search the specified element in the given array and returns the index of the last match. Syntax: array.lastIndexOf (element,index) Parameters: element: It is a required parameter and represents the element that has to be searched. index: It is an optional parameter and represents the index position from … Read more