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

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

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

  • Return every nth element in an array
  • Remove whitespaces from a string
  • Filter out matching array elements
  • Capitalize the first letter of every word in a string

Primary Sidebar

FREE UPDATES!

Get the latest updates in your inbox for FREE!

Popular Posts

Story Generator

IP Grabber

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2022 JavaScriptSource.com

  • About
  • Privacy Policy
  • Submit
  • FAQ
  • Jobs For Developers
  • Contact Us