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

86
Views
El accesor Getter se muestra indefinido en una clase JS

Digamos que tengo la siguiente clase...

 Class Person { constructor(name, drives = false) { this.name = name; this._drives = drives; } get drives() { return this._drives; } set drives(drives) { this._drives = drives; } }

Ahora digamos que almaceno un montón de objetos "Persona" en el almacenamiento local. Ahora quiero recorrer el almacenamiento local y encontrar la "Persona" que no conduce (creé 1 de cada 5 que tiene _unidades como VERDADERO). Cuando hago esto, todos vuelven como indefinidos... ¿por qué?

 const testFunction = () => { for (let i = 0; i <= localStorage.length; i++) { const key = localStorage.key(i); const storedObj = JSON.parse(localStorage.getItem(key)); if (!storedObj.drives === true) { console.log(storedObj.drives); } } } testFunction();

¿Qué pasa aquí?

about 4 years ago · Juan Pablo Isaza
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!