Monday, 16 May 2016

How to efficiently check if variable is Array or Object


How to efficiently check if variable is Array or Object

a = [1,2,3]
[1, 2, 3]
a.constructor === Object
false
a.constructor === Array
true
a = [1,2,3]
[1, 2, 3]
a = {'name' : 'ggg', 'age': '52'}
Object {name: "ggg", age: "52"}
a.constructor === Array
false
a.constructor === Object
true

1 comment:

  1. fter reading this blog i very strong in this topics and this blog really helpful to all... explanation are very clear so very easy to understand... thanks a lot for sharing this blog more info Ruby on Rails Online Course

    ReplyDelete