vue loop through array code example
Example 1: vue loop through object
<ul id="example-1">
<li v-for="item in items" :key="item.message">
{{ item.message }}
</li>
</ul>
Example 2: vue v-for loop array
<script src="https://cdn.jsdelivr.net/vue/latest/vue.js"></script>
<div id="sample">
<div v-if = "private.folders!=null" v-for="folder in private.folders">
{{folder.name}}
<div v-for="check in folder.checks">
{{check.name}}
</div>
</div>
</div>
Example 3: vue js v-for array index
<ul>
<li v-for="(val, index) in arr">
</li>
</ul>
Example 4: vue v-for loop array
new Vue({
el: '#sample',
data: {
private: {
folders : [{
name : 'folder1',
checks : [
{ name : 'check1.1' },
{ name : 'check1.2' }
]
},
{
name : 'folder2',
checks : [
{ name : 'check2.1' },
{ name : 'check2.2' }
]
}
]
}
}
})
Example 5: get object from list of objects in vuejs with condition
var data = {specs:[{Name:"Power",Value:"1"},{
Name:"Weight",Value:"2"},{Name:"Height",Value:"3"}]}
var valObj = data.specs.filter(function(elem){
if(elem.Name == "Power") return elem.Value;
});
if(valObj.length > 0)
console.log(valObj[0].Value)