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

194
Views
¿Puedes pasar una clave de objeto como parámetro? - Esbelta/JS

Estoy usando Svelte y mi componente quiere tomar una serie de objetos y una clave específica. Sin embargo, no quiere leer la clave cuando es una variable. Esto es lo que he intentado hasta ahora.

 export let data = []; export let key; function cleanUp(data, key) { for (let i = 0; i < data.length; i++) { let d = data[i].key; newArray.push(d); } }

¿Hay alguna manera de hacer funcionar esto?

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

0

Si la variable key contiene una cadena, puede acceder a la propiedad de un objeto con ese nombre con object[key] .

En tu ejemplo:

 let d = data[i][key];
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!