• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
JavaScriptSource

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

  • Home
  • Browse Snippets
    • Addon
    • Ajax
    • Buttons
    • Cookies
    • CSS
    • Featured
    • Forms
    • Games
    • Generators
    • Image Effects
    • Math Related
    • Miscellaneous
    • Multimedia
    • Navigation
    • Page Details
    • Passwords
    • Text Effects
    • Time & Date
    • User Details
Home / Miscellaneous / Return all elements in an array except for the first one

Return all elements in an array except for the first one

Return all elements in an array except for the first one

Return Array.prototype.slice(1) if Array.prototype.length is more than 1, otherwise, return the whole array.

const tail = arr => (arr.length > 1 ? arr.slice(1) : arr);


// EXAMPLES
tail([1, 2, 3]); // [2, 3]
tail([1]); // [1]

Source

https://www.30secondsofcode.org/js/s/tail

Miscellaneous

Related Snippets:

  • How to Make the First Letter of a String Uppercase in JavaScript
  • Destructing variable assignment
  • Insert an element before another one
  • Check if all elements in an array are equal

Primary Sidebar

JSON Compare

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2025 JavaScriptSource.com

  • About
  • Privacy Policy
  • FAQ
  • Jobs For Developers
Advertisement