Untitled
unknown
javascript
a year ago
650 B
2
Indexable
Never
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; }