I have an object with two types of data: Array
and String
:
{
"livingroom": [
{
"app": "",
"name": "s1",
"thumbnail": "https://storage.googleapis.com/peterbucket/istagingViewer/sigstaging.com.tw/Cuiti/study/web/thumb_floorplan1.jpg"
}
],
"study": [
{
"app": "",
"name": "s0",
"thumbnail": "https://storage.googleapis.com/peterbucket/istagingViewer/sigstaging.com.tw/Cuiti/study/web/thumb_floorplan3.jpg"
}
],
"outdoor": [],
"id": "-KF28-_Vdve-u3498eQ1",
"name": "Cuiti"
}
Right now I'm looping through all the values, and I want to return only the first non-empty array (in this case the value of livingroom
).
// Template
<div v-for="value in object" v-if="isFirstNonEmptyArray(value, object)">
// JavaScript
isFirstNonEmptyArray (value, object) {
if (value instanceof Array) {
if (value.length > 0) {
// What to do here?
}
}
},
But as you can see I'm stuck after checking that the value is not empty. What should I write next?