Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Articles by Abdul Rawoof
Page 3 of 3
How do we check if an object is an array in Javascript?
In JavaScript, typeof returns "object" for arrays, which makes it unreliable for array detection. There are three better approaches: Array.isArray(), the constructor property, and instanceof. The Problem with typeof typeof returns "object" for arrays, objects, and null − it cannot distinguish arrays from other objects ? let str = "Abdul Rawoof"; let arr = [1, 3, 5, 8]; let num = 90; let dict = {a: 1, b: 2}; console.log(typeof str); // "string" console.log(typeof arr); // "object" ← not "array" console.log(typeof num); // "number" console.log(typeof dict); // ...
Read MoreAdvertisements