Using Data in Svelte Pages
📖 Scenario: You are building a simple Svelte page to display a list of fruits with their colors. This is like making a small fruit catalog on a webpage.
🎯 Goal: Create a Svelte page that holds a list of fruits and their colors, then show them in a neat list on the page.
📋 What You'll Learn
Create a variable called
fruits that holds an array of objects with name and color properties.Create a variable called
highlightColor to store a color string.Use a
{#each} block to loop over fruits and display each fruit's name and color.Highlight the fruit name with the color stored in
highlightColor.💡 Why This Matters
🌍 Real World
Displaying lists of items with dynamic data is common in websites, like product catalogs or contact lists.
💼 Career
Knowing how to use data and loops in Svelte pages is essential for building interactive web apps and user interfaces.
Progress0 / 4 steps