You need to specify the iterator function as the second argument to _each
, i.e.:
var arr = [1,2,3,'hello',5]
function StringArray() {
for (var i = 0; i < arr.length; i++) {
if(typeof arr[i] ==='string') {
_.each(arr[i], function(element, index, list) {
console.log(element);
});
}
}
}
StringArray();
I also changed your var name from Array
to arr
to avoid overwriting the built-in Array.