array.unshift(element1, element2, ..., elementX)
Parameters: This method accepts a single parameter.
- element: This parameter element is to be added at the beginning of the array.
Return value: This function returns the new length of the array after inserting the arguments at the beginning of the array.
Example 1: Below is an example of the Array unshift() method.
let array = [
let value = array.unshift(
[ 'GeeksforGeeks', 'GFG', 'Geeks', 'for', 'Geeks' ]
Example 2: In this example, the function unshift() adds 28 and 65 to the front of the array.
let arr = [23, 76, 19, 94];
[ 28, 65, 23, 76, 19, 94 ]
Example 3: In this example, the unshift() method tries to add the element of the array, but the array is empty therefore it adds the value in the empty array.
let arr = ;
- Google Chrome 1 and above
- Edge 12 and above
- Firefox 1 and above
- Internet Explorer 5.5 and above
- Opera 4 and above
- Safari 1 and above
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!