

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to remove the 0th indexed element in an array and return the rest of the elements in JavaScript?
The _.rest() is used to return the rest of the elements except the zeroth indexed element. It belongs to underscore.js, a library of javascript. It takes two parameters. One is an array and the other is an index. The second parameter is used to start the search from the given indexed array.
syntax
_.rest( array, index );
Example
In the following example, the 0th indexed element was removed using _.rest() method. Here no second parameter was passed.
<html> <body> <script src ="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js" > </script> </head> <body> <script type="text/javascript"> document.write(_.rest([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])); </script> </body> </html>
Output
2, 3, 4, 5, 6, 7, 8, 9, 10
in the following example, the second parameter is also included. When a second parameter is provided, which is nothing but an index, those many numbers of elements will be removed and the rest of the elements will be displayed as shown in the output.
Example
<html> <body> <script src ="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js" > </script> </head> <body> <script type="text/javascript"> document.write(_.rest([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],4)); </script> </body> </html>
Output
5, 6, 7, 8, 9, 10
- Related Questions & Answers
- Remove values in an array by comparing the items 0th index in JavaScript?
- Return an array of all the indices of minimum elements in the array in JavaScript
- How to remove last array element in JavaScript and return it?
- How to remove first array element in JavaScript and return it?
- JavaScript Sum odd indexed and even indexed elements separately and return their absolute difference
- Maximum difference between the group of k-elements and rest of the array in C
- How to return an array whose elements are the enumerable property values of an object in JavaScript?
- Return the floor of the array elements in Numpy
- Absolute Difference of even and odd indexed elements in an Array (C++)?
- Java program to remove the duplicate element in an array
- Absolute Difference of even and odd indexed elements in an Array in C++?
- How to return the background color of an element with JavaScript DOM?
- How to duplicate elements of an array in the same array with JavaScript?
- Return the sum of two consecutive elements from the original array in JavaScript
- Return the Upper triangle of an array and set the diagonal above to zero elements in Numpy
Advertisements