Consider foolowing code snippet:
var arr =[];
How can you check if arr is array? Select all correct options.
Explanation
  • 1) if (arr) {}; // check if the object exists
  • 2) if (arr.splice){}; // we can check whether element has a splice() method that can have only array.
  • 3) Array.isArray(arr) // check using function isArray();
  • 4) if (arr.constructor === Array) // check throught contstructor;
  • 5) typeof(arr); // will return object
  • 6) arr instanceof Array - tests whether an object has in its prototype chain of Array object

@basimdev32 agree! But in some cases can be used, but probably wouldn't be good choice

2018 Feb 4, 5:52:54 PM

@nklskr20 thanks! fixed

2018 Feb 4, 5:51:54 PM

Of cause not only Array has splice method. For example, function MyClass(){ this.splice = 12; } any instance of MyClass will have splice property as well.

2018 Jan 28, 2:24:53 PM

The explanation has russian words.

2018 Jan 26, 5:07:48 AM

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
JavaScript quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes