this is the snippet: this code is not working, the problem it is not recognizing the array inside the array.
how can i improve it?
thanks!
<!DOCTYPE html>
<html>
<body>
<p>The new ECMASCRIPT 5 method isArray returns true when used on an array.</p>
<p id="demo"></p>
<script>
function findApple(arr, item) {
var count = 0;
for (var i = 0; i < arr.length; i++) {
if (Array.isArray(arr[i])) {
findApple(arr[i], item);
}
else if (arr[i] == "apple") {
count++;
}
}
return count;
}
var one = ["apple", "apple", ["orange", "apple", "banana"]];
var data = findApple(one, "apple");
alert(data);
var item = document.getElementById("demo").innerHTML = data;
</script>
</body>
</html>
findApple(arr[i], item);- you're not using the return value.it is not recognizing the array inside the arrayyeah, I don't think that is correct.itemotherwise there is no point in passing theitemvar in