Is this a good way to identify the type of a javascript object?
- by FK82
Apparently neither instanceof nor typeof deliver in terms of correctly identifying the type of every javascript object. I have come up with this function and I'm looking for some feedback:
function getType() {
var input = arguments[0] ;
var types = ["String","Array","Object","Function","HTML"] ; //!! of the top of my head
for(var n=0; n < types.length; n++) {
if( input.constructor.toString().indexOf( types[n] ) != -1) {
document.write( types[n] ) ;
}
}
}
Thanks for reading!