+ 4

What the type of arrays in javascript

18th Nov 2020, 6:31 AM
Maureen Muiru
Maureen Muiru - avatar
6 Answers
+ 5
console.log(typeof [ ]) //Outputs: object 👍
18th Nov 2020, 7:34 AM
David Carroll
David Carroll - avatar
+ 3
Homogeneous, Heterogeneous, Multidimensional and Jagged
18th Nov 2020, 6:39 AM
Lijo M Loyid
Lijo M Loyid - avatar
+ 3
If you wanna check that whether something is an array or not, you can use this: let words = "not an array" console.log(Array.isArray(words)) // false
18th Nov 2020, 12:09 PM
maf
maf - avatar
+ 1
David Carroll [].constructor === Array is the best way to determine if it's an array or object.
19th Nov 2020, 5:39 PM
Valtrius Malleus
Valtrius Malleus - avatar
+ 1
Ah... my answer might have given the impression that I wasn't sure why the output is object. I've changed my emoticon from 🤷‍♂️ to 👌. I was trying to convey to the OP... "Is this what you're asking?" But it just looked like I didn't understand the output. 🤦‍♂️
19th Nov 2020, 8:54 PM
David Carroll
David Carroll - avatar