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

215
Views
No se pueden cambiar los valores de propiedad del objeto con el bucle for-in

Tengo un problema extraño en JavaScript/Vue.js. Estoy tratando de recorrer las propiedades de un objeto (nuevo juego) y cambiar sus valores a 'indefinido'. Parecen tomar el valor cuando los consuelo. log() desde dentro del bucle for, pero "vuelven" a sus valores anteriores después del bucle. Estoy bastante seguro de que estoy pasando por alto algo aquí. Las propiedades de newGame también están vinculadas a algunos elementos de entrada con v-model. Aquí está el fragmento de código:

 data() { return { newGame: { id: undefined, date: undefined, location: undefined, length: undefined, limit: undefined, buyIn: undefined, cashOut: undefined }, games: Array }; }, methods: { addGame() { let newGameCopy = { ...this.newGame }; newGameCopy.id = uuidv4(); this.games = [...this.games, newGameCopy]; console.log(this.newGame); // This one doesn't work. for (let property in this.newGame) { console.log(property); property = undefined; console.log(property); } console.log(this.newGame); // This one works. this.newGame.id = undefined; this.newGame.date = undefined; this.newGame.length = undefined; this.newGame.limit = undefined; this.newGame.buyIn = undefined; this.newGame.cashOut = undefined; this.newGame.location = undefined; console.log(this.newGame); }, }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Reasignar un identificador, por sí mismo, no tendrá ningún efecto secundario (en la gran mayoría de las situaciones); a menos que use el identificador (aquí, property ) más adelante, asignarle algo (como undefined ) no tendrá ningún efecto. Debe asignar undefined al newGame , para mutar realmente el objeto:

 for (let property in this.newGame) { this.newGame[property] = undefined; }
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!