• 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:

  • Insert an HTML string before the start of the specified element
  • Return all the elements of an array except the last one
  • How to loop through arrays and array-like objects in JavaScript
  • Create a new array from an existing one

Primary Sidebar

JSON Compare

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2026 JavaScriptSource.com

  • About
  • Privacy Policy
  • FAQ
  • Jobs For Developers