Discussion icon indicating copy to clipboard operation
Discussion copied to clipboard

Get length of object values

Open opheliadesign opened this issue 10 years ago • 3 comments

I have the following data array that I need the size of:

{
  "users": {
    "asdasdasd": {
      "name": "Benjamin"
    }
  }
}

using users.length returns undefined. Any ideas?

opheliadesign avatar May 30 '15 17:05 opheliadesign

Object.keys(this.users).length

azamat-sharapov avatar May 31 '15 09:05 azamat-sharapov

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?

3dos avatar Nov 28 '17 09:11 3dos

vm.Object is undefined. You need to move such JS expressions out of template to VM.

azamat-sharapov avatar Nov 28 '17 11:11 azamat-sharapov