⊗jsvuPmLpAOO 31 of 72 menu

Iterating through an array of objects in Vue

Now let's learn how to iterate over an array of objects. Let's look at an example. Let's have the following array:

data() { return { users: [ { name: 'name1', surn: 'surn1', }, { name: 'name2', surn: 'surn2', }, { name: 'name3', surn: 'surn3', }, ] } }

Let's loop through our array and display the first and last name of each user in a separate paragraph:

<template> <p v-for="user in users"> {{ user.name }} {{ user.surn }} </p> </template>

The following array is given:

data() { return { hrefs: [ {href: '1.html', text: 'text1'}, {href: '2.html', text: 'text2'}, {href: '3.html', text: 'text3'}, ] } }

Using a loop, generate the following code:

<ul> <li><a href="1.html">text1</a></li> <li><a href="2.html">text2</a></li> <li><a href="3.html">text3</a></li> </ul>

The following array of products is given:

data() { return { products: [ { name: 'product1', price: 100, quantity: 5 }, { name: 'product2', price: 200, quantity: 4 }, { name: 'product3', price: 300, quantity: 3 }, ] } }

Using a loop, generate the following code:

<table> <tr> <td>product1</td> <td>100</td> <td>5</td> </tr> <tr> <td>product2</td> <td>200</td> <td>4</td> </tr> <tr> <td>product3</td> <td>300</td> <td>3</td> </tr> </table>
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline