I'm trying to count how many different data types are in this array, var arr. The output I am trying to return should be 2.
var arr = [12, 45, 66, 88, true, false]
var count = [];
function check_types(arr) {
for (i = 0; i <= typeof arr.length; i++) {}
return count;
}
check_types(arr)
I appreciate the feedback that helps me notice what I did wrong and so that I avoid repeating mistakes in future code. Thank you.
typeof arr.lengthalso makes no sense.i <= "number". What you did wrong is you have no logic in your code that actually checks the type.