Discussion
Discussion copied to clipboard
Get length of object values
I have the following data array that I need the size of:
{
"users": {
"asdasdasd": {
"name": "Benjamin"
}
}
}
using users.length returns undefined. Any ideas?
Object.keys(this.users).length
Hi, I tried Object.keys(someObject).length in a vue but it throws a
[Vue warn]: Error when evaluating expression "Object.keys(filteredHeadboards).length > 1": TypeError: Cannot read property 'keys' of undefined (found in component: <sidebar-headboard>)
In the vue:
<div v-for="(mandantId, headBoards) in filteredHeadboards">
<h2
class="panel-header"
v-if="Object.keys(filteredHeadboards).length > 1"
>@{{ mandantId }}</h2>
{{-- rest of the code --}}
</div>
Using vue 1.0.24 on an existing project. So Object, seems undefined. Why?
vm.Object is undefined. You need to move such JS expressions out of template to VM.