Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
JavaScript Array.isArray()
The Array.isArray() method of JavaScript is used to determine whether an object is an array or not.
The syntax is as follows −
Array.isArray(ob)
Above, the ob parameter is the object to be tested.
Let us now implement the Array.isArray() method in JavaScript −
Example
<!DOCTYPE html>
<html>
<body>
<h2>Ranking Points</h2>
<p>Is this an array? Click the below button to get the answer...</p>
<button onclick="display()">Result</button>
<p id="test"></p>
<script>
var pointsArr = [10, 20, 30, 40, 50, 60, 70, 80, 90, 1000];
var res = pointsArr.entries();
for (val of res) {
document.getElementById("test").innerHTML += val + "<br>";
}
function display() {
var res = document.getElementById("test");
res.innerHTML = Array.isArray(pointsArr);
}
</script>
</body>
</html>
Output

Click the “Result” button above −

Example
<!DOCTYPE html>
<html>
<body>
<h2>Demo Heading</h2>
<p>Is this is an array?</p>
<p id="test"></p>
<script>
var arr = ["Accessories", "Electronics", "Books", "Pet Supplies"];
var res = document.getElementById("test");
res.innerHTML = Array.isArray(arr);
</script>
</body>
</html>
Output

Advertisements