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

250
Views
How to fix error (cant access lexical declaration Array before initialization ) in react.js?

I set the array in onchange method and I see it in the console with console.log("array =",array) with all elemets but when I want to delete the duplicate element with Array.from(new Set(array)) method in the update method , I find error in the console ( cant access lexical declaration Array before initialization ) !

const [array, setArray] = useState([]); 

const update = (e) =>{ 

  e.preventDefault();  console.log("array =",array);  // = [ 1,  1, 2, 2, 51, 51 ] 
  
  if( array !==undefined){ 
  
    const Array = Array.from(new Set(array));    // error   } }
    
    setarticlesolde((pre) => {      
 
      setArray((pre) => [pre.articleId]);
      return  [... pre];
    })
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

It workin when I change

const Array = Array.from(new Set(array));

to

var arr =0; arr = Array.from(new Set(array));

you cant use Array like variable because it already defined as existe function in javascript(React.js)

about 4 years ago · Juan Pablo Isaza Report

0

Simply change your code to const arr = Array.from(new Set(array)). Array is js inner variable.

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!