JavaScript Spread & Rest Operators

const numbers =[1,2,3]const newNumbers =[...numbers, 4];console.log(newNumbers)
const person = {name: "Soner"};const newPerson = {...person,age:20}console.log(newPerson)
const filter = (...args) => {return args.filter(el => el === 1);}console.log(filter(1,2,3));

The spread operator is useful for many different routine tasks in JavaScript, including the following:

  • Copying an array
  • Concatenating or combining arrays
  • Using Math functions
  • Using an array as arguments
  • Adding an item to a list
  • Adding to state in React
  • Combining objects
  • Converting NodeList to an array


const address = [141E, 'Lexington ', 'NY'];
const [ houseNo, , city ] = address;
console.log(houseNo, city)
// 141E 'NY'



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Soner Mezgitci

Soner Mezgitci


Software Engineer | Ruby on Rails | JavaScript | HTML5 | CSS | PostgreSQL | React | Redux