What is the correct and best way to check the object is an array or not ?
$scope.studentArray= [{student1},{student2},{student3}];
What is the correct and best way to check the object is an array or not ?
$scope.studentArray= [{student1},{student2},{student3}];
Please use this http://docs.angularjs.org/api/ng/function/angular.isArray
angular.isArray($scope.studentArray);
I would install Underscore.js and use the isArray function like so:
_.isArray($scope.studentArray);
What about:
if(Object.prototype.toString.call($scope.studentArray) === '[object Array]') {
// is array
}
Cleanest solution without any libraries would be:
var arr = ['val1','val2','val3'];
console.log(arr instanceof Array); // true
var astring = 'test';
console.log(astring instanceof Array); // false;