I am having an array of comma separated objects like... new_data = [ Max:500 , Ron:200 ],I want to iterate over the array giving a list as Max-500 and Ron 200 In html it would look like
CodePudding user response:
You can map
your array:
let new_data = ['Max:500', 'Ron:200'].map(item => item.split(':'))
Then use #each
like:
<ul>
{#each new_data as data}
<li>{data[0]}-{data[1]}</li>
{/each}
</ul>
Working example: https://svelte.dev/repl/ba06eae1002345118bc3b645edb7049a?version=3.46.4
CodePudding user response:
Or like this
<script>
let new_data = ['Max:500', 'Ron:200']
</script>
<ul>
{#each new_data as data}
<li>{data.replace(':','-')}</li>
{/each}
</ul>