Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 equivalent of angular.isArray

Tags:

angular

Im playing around with NG2 and I am looking for the equivalent of angular.isArray.

Yes, I tried to google it but no luck. Im probably thinking about this problem.

The method I try to use in my ng2-app is this:

function periodsFormat(dates, func) {
  if (!angular.isArray(dates)) { return func(dates); }
  return dates.map(func).join('-');
}

Surely it should work if I manage to replace (!angular.isArray... with something NG2-ish. Thank you!

Update:

Thank you both, I ended doing this:

function periodsFormat(dates, func) {
  if (!Array.isArray(dates)) { return func(dates); }
  return dates.map(func).join('-');
}
like image 989
user2915962 Avatar asked Nov 12 '15 15:11

user2915962


1 Answers

I suspect you can just check the ctor:

if (dates.constructor !== Array) { ...

Since I believe you wouldn't be dealing with possible wrapped objects anymore.

Angular 1 checked for jQuery/jLite array's if I remember correctly which is why there was a special function for checking arrays.

like image 126
Phill Avatar answered Nov 10 '22 10:11

Phill