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

470
Views
How to iterate over a json dictionary in Svelte

In Svelte, the #each construct can be used to iterate over an array-like object. If one has a JSON dictionary object instead, does Svelte provide a way to iterate over the JSON dictionary in order to populate a dropdown menu? My data is the result of an API call and looks like:

const obj = { foo: "bar", batz: "boink" }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You first convert your object to an array with the infos (keys/values/boths) you would like to display.
This array is then iterable with an #each loop. See this REPL

<script>
const obj = { foo: "bar", batz: "boink" }

let keys = Object.keys(obj)  // ["foo", "batz"]
let values = Object.values(obj)  // ["bar", "boink"]
let entries = Object.entries(obj)  // [["foo", "bar"], ["batz", "boink"]]

</script>

{#each entries as [key, value]}
    <div>
    {key} - {value} 
    </div>  
{/each}

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!