0

index.js

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {

  $scope.data =[{"Id":1,"Title":"en-US","Description":"UnitedStates","MyValues":[{"demo":"dish","Id":100,"Value":"Save"}]},
{"Id":1,"Title":"en-UK","Description":"UK","MyValues":[{"demo":"Myvalu","Id":102,"Value":"Delete"}]}]
  $scope.cols = Object.keys($scope.data[0]);

  $scope.notSorted = function(obj){
    if (!obj) {
        return [];
    }
    return Object.keys(obj);
}  
});

I want to check in $scope.data is there any column value as array/collection in above code MyValues is a array/collection , I tried using angular.isArray(value) but it does not work , any help?

Neo
  • 15,491
  • 59
  • 215
  • 405

2 Answers2

2

You can use this check Array.isArray([1,2,3])

$scope.data.map(function(obj){
  return Object.keys(obj).filter(function(k){
       return Array.isArray(obj[k]);
    });
});

The code above will give you all the lists for each element in the Array of $scope.data ,, do you want a specific format ??

Ahmed Eid
  • 1,145
  • 8
  • 9
  • yup its work as expected actually I tried this to find out answer for this question check out http://stackoverflow.com/questions/31447821/how-do-i-generate-nested-table-in-one-column-if-it-has-list-of-values-using-angu – Neo Jul 16 '15 at 17:52
  • if you able to answer this question also it will be great help thanks http://stackoverflow.com/questions/31447821/how-do-i-generate-nested-table-in-one-column-if-it-has-list-of-values-using-angu – Neo Jul 16 '15 at 17:53
1

Better technique is to use the some() with angular.isArray():

if($scope.data.some(angular.isArray)) {
   //do awesome stuff
}
deostroll
  • 11,661
  • 21
  • 90
  • 161
  • but how do I used this in table tag? in html? – Neo Jul 17 '15 at 08:25
  • i tried to achieve this, http://stackoverflow.com/questions/31447821/how-do-i-generate-nested-table-in-one-column-if-it-has-list-of-values-using-angu – Neo Jul 17 '15 at 09:11