getType function for js

this function returns the type of item, array object string number etc

Javascript

const getType = (value) => Object.prototype.toString.call(value).slice(8, -1).toLowerCase();

anArray = ["array"];
var anObject = { obj1: "yo", obj2: "yoel" };

console.log(getType(anArray));
console.log(getType(anObject));

Demo

Other Items in javascript
Page Views

This page has been viewed 56 times.

Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

❤👩‍💻🕹