Untitled
unknown
javascript
3 years ago
650 B
11
Indexable
function strCount(obj){
const keys = Object.keys(obj);
let counter = 0;
for (let i = 0; i < keys.length; i++){
const item = obj[keys[i]];
if (typeof item === 'string') counter += 1;
else if (Array.isArray(item)) {
for (let j = 0; j < item.length; j++){
if (typeof item[j] === 'string') counter += 1;
else if (typeof item[j] === 'object' && typeof item[j] !== 'undefined' && item[j] !== null){
counter += strCount(item[j])
}
}
}
else if (typeof item === 'object' && typeof item !== 'undefined' && item !== null){
counter += strCount(item)
}
}
return counter;
}Editor is loading...