You might also be able to find a solution fromAI solution orcommunity posts solution for JavaScript Coding Question
20. Detect data type in JavaScript


Detecting in data type


1. Firstly, we need to find out the string representing the Object that can be achieved through Object.prototype.toString, basically in JavaScript, each built-in type has its own toString method And for Object It will return like this
eg: const arr = [1,2,3,4] // return [object Array]
const str ='hello' // return [object String]
2. We need a regex now to bifurcate the return object (/[object (.*)]/g)
3. Now we need to execute the rawObject with the regex to find out the correct data type
4. Lastly return the exact type which we get it from executing the regex.
 ***Simpler implementation***

const detectType = (input) => {
	const rawObject =;
	const typeRegex = /\[object (.*)]/g;
	const type = typeRegex.exec(rawObject)[1];
	return type;
eg: detectType([1,2,3,4]) // return array

detectType({a: 1, b: 1}); // return object

detectType(new Date()) // return date

detectType(new Map()) // return map

detectType( () => console.log('hello')) // return function
This will not be achieved through built-in typeof method in javascript.

typeof(new Map()) // return object

typeof([1,2,3]) // return object

typeof({a: 1, b:1}) // return object

typeof(new Date()) // return object

Would you like to contribute to the solution? Contribute guideline