jose
jose

Reputation: 1054

how to take inside array count in angularjs

hi all i am using angularjs i have one object inside some of data now i need to take the count of an a object array here i attached my code help how to do this

$scope.data = {
    "label": "Information",
    "fields": [{
      "name": "name",
      "label": "Team Name",
      "type": "string",
      "config": {}
    }]
 }

here i want take fields count or length

Upvotes: 0

Views: 61

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222657

fields is an array inside the data, so you could just use length.

var fieldscount = data.fields.length;

EDIT Since you need the count of fields inside the object, you can just use Object.keys,

Object.keys(data.fields[0]).length

DEMO

var data = {
    "label": "Information",
    "fields": [{
      "name": "name",
      "label": "Team Name",
      "type": "string",
      "config": {}
    }]
 }
 console.log(Object.keys(data.fields[0]).length);

Upvotes: 3

Related Questions