I want to know about some function (if any) or library which may provide direct functions to find the type of elements in an array.
Suppose I have an array containing elements of same data type :
var sameArray = [1, 2, 3, 4];
var diffArray = ['a', 'b', 'c', 4];
sameArray.itemPrototype(); // Returns int
diffArray.itemPrototype(); // Returns undefined
For first array, it should return int and for the second one undefined or false.
itemPrototype?...Any custom function you wrote?int, but as second case have multiple types present, so expected output should beundefinedas you mentioned..Right? If thats the case, you can simply write a custom function, probably usingtypeofinside it..