How to print both Object key and value with Each block in Svelte? - Stack Overflow


Sun Jul 25 2021 12:17:04 GMT+0000 (UTC)

Saved by @joannpav #svelte

    const sections = {
        "Title 1": "paragraph",
        "Title 2": "paragraph",
        "Title 3": "paragraph",
        "Title 4": "paragraph",
        "Title 5": "paragraph"
    // Object.entries() converts an Object into an array of arrays, 
    // each sub array first index is the a key and the second index is a value
    // Object.entries({key: value, key:value}) => [[key, value], [key,value]]

{#each Object.entries(sections) as [title, paragraph]}