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

201
Views
Can you pass an object key as a param? - Svelte/JS

I'm using Svelte and my component wants to take in an array of objects and a specific key. However it doesn't want to read the key when it is a variable. This is what I've tried so far.

  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);
    }
  }

Is there anyway to make this work?

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

0

If the key variable contains a string, you can access an object's property with that name with object[key].

In your example:

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!