_.rest() จาก underscore.js ใช้คืนค่าอิลิเมนต์ที่เหลือหลังจากตัดดัชนีที่ 0 ออก รับพารามิเตอร์ 2 ตัว คือ อาร์เรย์ และดัชนีเริ่มต้น (optional)
ไวยากรณ์
_.rest(array, index);
ตัวอย่าง ไม่ระบุดัชนีที่ 2 (ตัดแค่ตัวแรก)
<html> <body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js"></script>
<script type="text/javascript">
document.write(_.rest([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]));
</script> </body> </html>
ผลลัพธ์
2, 3, 4, 5, 6, 7, 8, 9, 10
ตัวอย่าง ระบุดัชนีที่ 2 (ตัด 4 ตัวแรก)
<html> <body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js"></script>
<script type="text/javascript">
document.write(_.rest([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 4));
</script> </body> </html>
ผลลัพธ์
5, 6, 7, 8, 9, 10