You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
571 B
JavaScript
20 lines
571 B
JavaScript
function detect_data_type(value)
|
|
{
|
|
var dtypes = [Function, RegExp, Number, String, Boolean, Object], x, len;
|
|
|
|
if (typeof value === "object" || typeof value === "function")
|
|
{
|
|
for (x = 0, len = dtypes.length; x < len; x++)
|
|
{
|
|
if (value instanceof dtypes[x])
|
|
{
|
|
return dtypes[x];
|
|
}
|
|
}
|
|
}
|
|
|
|
return typeof value;
|
|
}
|
|
console.log(detect_data_type(12));
|
|
console.log(detect_data_type('w3resource'));
|
|
console.log(detect_data_type(false));
|