/*please have a look at the following function. Its a simple function. I want to iterate over the movies array and return the element; only if the element's title is exactly same as the argument passed in. otherwise return false at the end of the iteration.
The problem is, it always return false. However, if I use a regular forloop instead of forEach loop, it works perfectly fine.. can someone please explain why is this situation?????? Thank You in advance. */
function searchMovies(title) { movies.forEach(function(ele){ if(ele.title === title){ return ele; } }); return false; } //movies array var movies = [ {title: 'The Hobbit'}, {title: 'The Great Gatsby'}, {title: 'Gone with the Wind'} ]; //the following line calls the function searchMovies('The Great Gatsby');