Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • 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
  • 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:
What does '...' mean in JavaScript?
Next article icon

What does '...' mean in JavaScript?

Last Updated : 07 Mar, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The '...' (or 3 dot symbol) in JavaScript is known as the Spread operator or Rest operator based on the usage. This syntax is used to expand the iterable into individual elements such as arrays, objects, etc.

Syntax for Spread Operator

cosnt a1 = [ 10, 20, 30, 40 ];
const a2 = [ ...a1, 50]; // Extracting the array elements using Spread Operator
// Final value of a2 => [ 10, 20, 30, 40, 50 ]

Syntax for Rest Parameter

const a  = [ 10, 20, 30, 40, 50 ]
const [ a1 , ... restA ] = a; // Destructureing the aray using Rest Operator
// Final value of a1 => 10, restA => [ 20, 30, 40, 50 ]

The meaning of "..." in JavaScript can be interpreted in the following context.

Spread Operator (...)

The spread operator takes an array or object and spreads its elements or properties into individual components. It’s typically used when we need to pass an array’s elements into a function, combine arrays, or clone objects.

Now let's understand the uses of spread operator using some examples:

Spreading Arrays

One common use of the spread operator is to easily expand arrays. This is useful when we want to combine arrays or make copies without altering the original.

Example: This example creates a new array by adding few elements in the given array.

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

Output
[ 10, 20, 30, 40, 50 ] 

Passing Array Elements as Function Arguments

The spread operator can also be used to pass array elements as individual arguments to a function.

Example: This example passes the array using spread operator to pass individual elements as arguments.

JavaScript
const a = [10, 20, 30]; const maxNum = Math.max(...a);  console.log(maxNum); 

Output
30 

Cloning Arrays

The spread operator makes it simple to create shallow copies of arrays.

Example: This example creates a clone of the given array using spread operator.

JavaScript
const a1 = ['apple', 'banana', 'cherry']; const a2 = [...a1];  console.log(a2); 

Output
[ 'apple', 'banana', 'cherry' ] 

Spreading Objects

The spread operator can also be applied to objects it allows us to copy or merge them.

Example: This example creates a new object with exetended properties using the given object.

JavaScript
const obj1 = { name: 'Ajay', age: 25 }; const obj2 = { ...obj1, city: 'New York' };  console.log(obj2); 

Output
{ name: 'Ajay', age: 25, city: 'New York' } 

Rest Operator (...)

The rest operator is the inverse of the spread operator. While the spread operator expands elements, the rest operator collects multiple elements or properties into a single entity, usually an array.

Now let's understand uses of rest operator using some examples:

Using Rest in Function Parameters

The most common use of the rest operator is in function parameters where you don’t know how many arguments will be passed. The rest operator gathers all arguments into an array.

Example: This example convertes the array passed as arguments into individual elements in function declaraion using rest parameter.

JavaScript
function sum(...numbers) {     return numbers.reduce((total, num) => total + num, 0); }  console.log(sum(1, 2, 3)); console.log(sum(4, 5, 6, 7)); 

Output
6 22 

Destructuring Arrays with Rest

The rest operator can also be used in array destructuring to collect the remaining elements after certain ones are assigned.

Example: This example separates or destructure the elements as first, second and rest elements.

JavaScript
const [first, second, ...rest] = [10, 20, 30, 40, 50];  console.log("First element =", first); console.log("Second element =", second); console.log("Rest elements =", rest); 

Output
First element = 10 Second element = 20 Rest elements = [ 30, 40, 50 ] 

Destructuring Objects with Rest

The rest operator can also be used to extract specific properties from an object, while collecting the remaining properties in a new object.

Example: This example desctructures the object and extracts properties from the object.

JavaScript
const o = { name: 'Sandeep', age: 30, city: 'Jaipur', profession: 'CEO' }; const { name, ...rest } = o;  console.log(name); console.log(rest); 

Output
Sandeep { age: 30, city: 'Jaipur', profession: 'CEO' } 

Next Article
What does '...' mean in JavaScript?

G

ghuleyogesh
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • JavaScript-Questions

Similar Reads

    What does +_ operator mean in JavaScript ?
    Unary Operator: A unary operation contain only one operand. Here, the '+' unary plus operator converts its operand to Number type. While it also acts as an arithmetic operator with two operands which returns an addition result on calculation. JavaScript Identifiers: Javascript Identifiers are used t
    2 min read
    What does !== undefined mean in JavaScript ?
    In JavaScript, !== is a strict inequality operator, and undefined is a special value representing the absence of a value or the lack of an assigned value to a variable. The !== operator checks for both value and type equality, and !== undefined is used to verify if a variable is not equal to the und
    1 min read
    What Does javascript:void(0) Mean?
    javascript:void(0) is commonly used in HTML to create a link that doesn’t perform any action or navigate to a new page. When placed in the href attribute of an <a> tag, it allows the link to execute JavaScript code without reloading or changing the current page. This is particularly useful for
    4 min read
    What is JavaScript?
    JavaScript is a powerful and flexible programming language for the web that is widely used to make websites interactive and dynamic. JavaScript can also able to change or update HTML and CSS dynamically. JavaScript can also run on servers using tools like Node.js, allowing developers to build entire
    6 min read
    What is $ {} in JavaScript ?
    In JavaScript, the ${} syntax is used within template literals, also known as template strings. Template literals, introduced in ECMAScript 6 (ES6), provide a convenient way to create strings with embedded expressions. They are enclosed within backticks (`) instead of single quotes ('') or double qu
    2 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