Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js get type


function gettype(data) {
            let itemType = Object.prototype.toString.call(data)
            let type = ''

            switch (itemType) {
                case "[object Null]":
                    type = 'Null';
                    break;

                case "[object Object]":
                    type = 'Object';
                    break;

                case "[object Array]":
                    type = 'Array';
                    break;

                case "[object String]":
                    type = 'String';
                    break;

                case "[object Boolean]":
                    type = 'Boolean';
                    break;

                case "[object Number]":
                    type = 'Number';
                    break;
            }

            return type
        }
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #js #type
ADD COMMENT
Topic
Name
1+5 =