In this article, you will learn about the javascript Array built-in method Array.prototype.isArray()
. How does this method work in javascript?
The Array.prototype.isArray()
method checks whether the passed value is an array or not. It returns true
if the value is an Array
; otherwise, it returns false
. It returns always false
if the value is a TypedArray instance.
array.isArray(value);
This method takes 1 parameter as given below:
Here are some examples of Array.prototype.isArray()
method:
//Here some examples of Array.isArray() Method
console.log(Array.isArray([]));
// Output => true
console.log(Array.isArray([1]));
// Output => true
console.log(Array.isArray(new Array()));
// Output => true
console.log(Array.isArray(new Array("a", "b", "c", "d")));
// Output => true
console.log(Array.isArray(new Array(3)));
// Output => true
// Little known fact: Array.prototype itself is an array:
console.log(Array.isArray(Array.prototype));
// Output => true
console.log(Array.isArray());
// Output => false
console.log(Array.isArray({}));
// Output => false
console.log(Array.isArray(null));
// Output => false
console.log(Array.isArray(undefined));
// Output => false
console.log(Array.isArray(17));
// Output => false
console.log(Array.isArray("Array"));
// Output => false
console.log(Array.isArray(true));
// Output => false
console.log(Array.isArray(false));
// Output => false
console.log(Array.isArray(new Uint8Array(32)));
// Output => false
// This is not an array, because it was not created using the
// array literal syntax or the Array constructor
console.log(Array.isArray({ __proto__: Array.prototype }));
// Output => false
I hope this article will help you to understand the javascript Array built-in method Array.prototype.isArray().
Share your valuable feedback, please post your comment at the bottom of this article. Thank you!
Comments