0

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

2
  • Is data coming from a REST call? Which version of angular? You want to get length from controller or from template? Commented May 11, 2017 at 6:08
  • it's scope variable i update my question @sabithpocker Commented May 11, 2017 at 6:28

1 Answer 1

3

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);

Sign up to request clarification or add additional context in comments.

1 Comment

i need fields count i need output 4@Sajeetharan name,label,type,config total 4 i need

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.