JavaScript Array unshift() method17 Mar 2025 | 1 min read The JavaScript array unshift() method adds one or more elements in the beginning of the given array and returns the updated array. This method changes the length of the original array. SyntaxThe unshift() method is represented by the following syntax: Parameterelement1,element2,....,elementn - The elements to be added. ReturnThe original array with added elements. JavaScript Array unshift() method exampleLet's see some examples of unshift() method. Example 1Here, we will add an element in the given array. Test it NowOutput: JQuery,AngularJS,Node.js Example 2Let's see an example to add more than one elements in the given array. Test it NowOutput: Length before invoking unshift(): 2 Length after invoking unshift(): 4 Updated array: JQuery,Bootstrap,AngularJS,Node.js Next TopicJavaScript Array |
JavaScript Array copyWithin() method The JavaScript array copyWithin() method copies the part of the given array with its own elements and returns the modified array. This method doesn't change the length of the modified array. Syntax The copyWithin() method is represented by the following syntax: array.copyWithin(target, start, end) Parameter target -...
1 min read
JavaScript Array method The JavaScript array method returns the index of first element of the given array that satisfies the provided function condition. It returns -1, if no element satisfies the condition. Syntax The method is represented by the following syntax: array.findIndex(callback(value,index,arr),thisArg) Parameter callback - It...
1 min read
JavaScript Array Method The methods perform testing and checks if atleast a single array element passes the test, implemented by the provided function. If the test is passed, it returns true. Else, returns false. Note: If method is applied on an empty array, it...
2 min read
JavaScript Array method The JavaScript array method is used to search the position of a particular element in a given array. This method is case-sensitive. The index position of first element in an array is always start with zero. If an element is not present...
1 min read
JavaScript Array Method The method creates and returns a new iterator object which holds the key for every index in the array. This method does not affect the original array. Syntax array.; Parameter It does not hold any parameter. Return It returns a new array iterator object. JavaScript Array Example Let's...
2 min read
JavaScript Array Method The method is used to test whether the value passed is an array. If it finds the passed value is an array, it returns True. Otherwise, it returns False. Syntax Array.isArray(obj_value); Parameter obj_value: It is the value of the object which is passed for determining...
2 min read
JavaScript Array Method The method creates a new iterator object of an array, holding the key/value pairs for every value in the array. A key represents the index number carrying an item as its value. It does not affect the original array. Syntax The following syntax...
2 min read
JavaScript Array method The JavaScript array method extracts the part of the given array and returns it. This method doesn't change the original array. Syntax The method is represented by the following syntax: array.slice(start,end) Parameter start - It is optional. It represents the index from where the method...
1 min read
JavaScript Array Method The method is an inbuilt array method that flattens a given array into a newly created one-dimensional array. It concatenates all the elements of the given multidimensional array, and flats upto the specified depth. We can specify the depth limit to...
2 min read
JavaScript Array Method The method is a combination of flat() and map() methods. This method initially maps each array element through a mapping function, then flatten up the array with depth value as 1. Syntax var newArr=arr.flatMap(function callback(currentValue[ , index[ , array]]) { return element } [ , thisArg]) Parameters callback-...
2 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India