On Feb 2, 2015, at 3:38 PM, Thomas Shinnick wrote:
> Whenever you see something you don't recognize, that just might be part of Javascript you didn't know about, try checking with one of the Javascript reference sites. I'm sure there are a few opinions which is 'best', but I just check the Mozilla site, such as searching for "mdn javascript foreach" with Google which gets you to Array.prototype.forEach()
> But what you have cited seems to be missing a callback reference, like
>
> list.foreach( function(file){
> if file.ext = ext then {
> console.log(item[i]
> }
> });
>
> Can you look at that "official answer" again?
Let's also not forget to capitalize "forEach" correctly; that we need parentheses around the conditional; that we want to compare, not assign; that there is no such JavaScript keyword as "then"; and that in the revised code, there is no variable "i":
list.forEach(function (file) {
if (file.ext == ext) {
console.log(file);
}
});
There's also no such thing as a "list" in JavaScript; it's called an "array". More here:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array