Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
what is the purpose of ...this.props.pokemon and how's it different from this.props.pokemon

I have been working on a simple react project wherein I found this snippet

 let hand1 =[]
    let hand2 =[ ...this.props.pokemon];
    while(hand1.length < hand2.length){
        let randIdx = Math.floor(Math.random()*hand2.length);
        let randPokemon = hand2.splice(randIdx,1)[0];
        hand1.push(randPokemon)
    }

What is the use of ..this.props.pokemon here?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

It is Spread syntax (...)

In your case, it deep copy pokemon array from your props and prevent mutate the original array/object

Take a look at this example where spread syntax is not used:

const firstArray = [1, 2];

const secondArray = firstArray;

secondArray[0] = 9;

console.log(firstArray);

And here is when spread syntax is used

const firstArray = [1, 2];

const secondArray = [...firstArray];

secondArray[0] = 9;

console.log(firstArray);

about 4 years ago · Juan Pablo Isaza Report

0

let hand2 = [ ...this.props.pokemon]

The above expression takes all the values inside this.props.pokemon and puts it inside the hand2 array.

For eg:

const fruits = ['apple', 'banana']
const breakfast = [...fruits, 'milk']

console.log(breakfast) -> ['apple', 'banana', 'milk']

Whereas if you don't have the spread operator(...). It'll put the whole array there instead of just the values. For eg:

const fruits = ['apple', 'banana']
const breakfast = [fruits, 'milk']

console.log(breakfast) -> [['apple', 'banana'], 'milk']
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!