See
typeof - JavaScript | MDN[
^].
If you only need to count the total number then you only need a single counter. Set it to zero at the beginning of the loop, and increment it for every type that is found. The second if/else block is not needed.
[edit]
Something like the following is a simpler way:
function check_types(array) {
var counts = [0, 0, 0, 0, 0, 0, 0, 0];
for (let i = 0; i < array.length; i++) {
if (typeof array[i] == "string") {
counts[0] = 1;
} else if (typeof array[i] == "number") {
counts[1] = 1;
} else if (typeof array[i] == "boolean") {
counts[2] = 1;
} else if (typeof array[i] == "object") {
counts[3] = 1;
} else if (typeof array[i] == "function") {
counts[4] = 1;
} else if (typeof array[i] == "null") {
counts[5] = 1;
} else if (typeof array[i] == "array") {
counts[6] = 1;
} else if (typeof array[i] == "undefined") {
counts[7] = 1;
}
}
total = 0;
for (let i = 0; i < counts.length; i++) {
total += counts[i];
}
return total;
}