Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Array
  • JS String
  • JS Object
  • JS Operator
  • JS Date
  • JS Error
  • JS Projects
  • JS Set
  • JS Map
  • JS RegExp
  • JS Math
  • JS Number
  • JS Boolean
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
Open In App
Next Article:
How to Check if an Element Exists in an Array in JavaScript?
Next article icon

How to Get all Elements Except First in JavaScript Array?

Last Updated : 23 Jan, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Here are the various methods to get all elements except the first in JavaScript Array

1. Using for loop

We will use a for loop to grab all the elements except the first. We know that in an array the first element is present at index '0'.

JavaScript
const a1 = [1, 2, 3, 4, 5]; const a2 = []; let k = 0;  for (let i = 1; i < a1.length; i++) {     a2[k] = a1[i];     k++; }  console.log(a2); 

Output
[ 2, 3, 4, 5 ] 

In this example

  • The code initializes an empty array find and a variable k for indexing.
  • A for loop starts from the second element (i = 1) of the original array.
  • Elements from the second position onward are copied to the find array.
  • The result is printed without using a separate function.

2. Using slice() Method

The slice() is a method that returns a slice of an array. It takes two arguments, the start and end index.

JavaScript
const a = [10, 20, 30, 40, 50]; const res = a.slice(1);  console.log(res); 

Output
[ 20, 30, 40, 50 ] 

In this example

  • The slice method is directly applied to the array a, starting from the second element (index 1).
  • The result is stored in the result variable and printed, avoiding the use of a separate function.

3. Using Array.filter method

The Array.filter() method is used to create a new array with elements from the existing array which satisfies the condition.

JavaScript
const a = [10, 20, 30, 40, 50]; console.log(a.filter((x, y) =>  	y != 0)); 

Output
[ 20, 30, 40, 50 ] 

In this example

  • The code uses the filter method to create a new array, excluding the element at index 0 (the first element) by checking if the index (y) is not equal to 0.

4. JavaScript Array.reduce() Method

The Array.reduce() is used to perform the function on each element of an array and form a single element. 

JavaScript
const a = [10, 20, 30, 40, 50]; console.log(a.reduce((a, x, i) =>  	(i == 0) ? a : a.concat(x), [])); 

Output
[ 20, 30, 40, 50 ] 

In this example

  • The code uses reduce to accumulate a new array, starting with an empty array, and skips the first element (index 0) by checking if the index is not equal to 0 before concatenating the remaining elements.

5. Using shift() Method

The JavaScript Array shift() Method removes the first element of the array thus reducing the size of the original array by 1.

JavaScript
let a = [34, 234, 567, 4]; a.shift(); console.log(a); 

Output
[ 234, 567, 4 ] 

In this example

  • The code uses shift to remove the first element from the array, and then logs the modified array, which no longer includes the first element.

6. Using Array.from() Method

The Array.from() method creates a new array instance from an array-like or iterable object.

JavaScript
const a = [10, 20, 30, 40, 50]; console.log(Array.from(a).slice(1)); 

Output
[ 20, 30, 40, 50 ] 

In this example

  • The Array.from method creates a shallow copy of the array, and slice(1) removes the first element, resulting in [20, 30, 40, 50].

7. Using splice() Method

The splice() method can be used to change the contents of an array by removing or replacing existing elements and/or adding new elements in place

JavaScript
const a = [10, 20, 30, 40, 50];  let res = a.slice(); res.splice(0, 1); console.log(res); 

Output
[ 20, 30, 40, 50 ] 

In this example

  • The slice() creates a shallow copy of the array, and splice(0, 1) removes the first element from the copied array, resulting in [20, 30, 40, 50].

8. Using Array.prototype.flatMap()

The flatMap() method can be used creatively to ignore the first element of an array by mapping the array to a sub-array that excludes the first element and then flattening the result.

JavaScript
const a = [10, 20, 30, 40, 50]; const res = a.flatMap((_, index) =>  	index === 0 ? [] : [a[index]]); console.log(res); 

Output
[ 20, 30, 40, 50 ] 

In this example

  • The flatMap method creates a new array by skipping the first element (index 0) and adding the remaining elements, resulting in [20, 30, 40, 50].

Next Article
How to Check if an Element Exists in an Array in JavaScript?
author
hritikrommie
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • javascript-array
  • JavaScript-DSA
  • JavaScript-Methods
  • JavaScript-Questions

Similar Reads

  • JavaScript - How to Get First N Elements from an Array?
    There are different ways to get the first N elements from array in JavaScript. Examples: Input:arr = [1, 2, 3, 4, 5, 6], n = 3 Output: [1, 2, 3] Input:arr = [6, 1, 4, 9, 3, 5, 7], n = 4Output: [6, 1, 4, 9]1. Using slice() MethodThe slice() method is used to extract a part of an array and returns a n
    4 min read
  • How to Check if an Element Exists in an Array in JavaScript?
    Given an array, the task is to check whether an element present in an array or not in JavaScript. If the element present in array, then it returns true, otherwise returns false. The indexOf() method returns the index of first occurance of element in an array, and -1 of the element not found in array
    2 min read
  • How to Filter an Array in JavaScript ?
    The array.filter() method is used to filter array in JavaScript. The filter() method iterates and check every element for the given condition and returns a new array with the filtered output. Syntax const filteredArray = array.filter( callbackFunction ( element [, index [, array]])[, thisArg]);Note:
    2 min read
  • JavaScript - How to Remove an Element from an Array?
    Removing elements from an array is a fundamental operation in JavaScript, essential for data manipulation, filtering, and transformation. This guide will explore different methods to efficiently remove elements from an array, enhancing your understanding and capability in handling arrays. 1. Using p
    3 min read
  • Remove Elements From a JavaScript Array
    Here are the various methods to remove elements from a JavaScript Array 1. Using pop() methodThe pop() method removes and returns the last element of an array. This function decreases the length of the array by 1 every time the element is removed. [GFGTABS] javascript let a = ["Apple",
    6 min read
  • How to Filter an Array from all Elements of another Array In JavaScript?
    Filtering one array from all elements of another array is a common task in JavaScript. This involves removing elements from one array that are present in another array. In this article we will explore different approaches to filter an array from all elements of another array in JavaScript. These are
    4 min read
  • How to Remove Multiple Elements from Array in JavaScript?
    Here are various methods to remove multiple elements from an array in JavaScript 1. Using filter() MethodThe filter() method creates a new array with the elements that pass the condition. This method does not change the original array. [GFGTABS] JavaScript let a = [1, 2, 3, 4, 5]; let remove = [2, 4
    4 min read
  • How to Remove First and Last Element from Array using JavaScript?
    Removing the first and last elements from an array is a common operation. This can be useful in various scenarios, such as data processing, filtering, or manipulation. Example: Input: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]Output: [ 2, 3, 4, 5, 6, 7, 8, 9 ]Removing first and last element in array can be d
    2 min read
  • How to delete an element from an array using JavaScript ?
    The array is a type of data structure that allows us to store similar types of data under a single variable. The array is helpful to create a list of elements of similar types, which can be accessed using their index. In this article, we will discuss different ways to remove elements from the array.
    5 min read
  • JavaScript – Min Element in an Array
    These are the following ways to find the minimum element in JS array: Note: You must add a conditional check for checking whether the given array is empty or not, if the array is not empty then you can use the given below approaches to find out the minimum element among them. 1. Using Math.min() Met
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences