I want to compare each string in an Array with a given string. My current implementation is:
function startsWith(element) { return element.indexOf(wordTo
The second parameter of filter will set this inside of the callback.
arr.filter(callback[, thisArg])
So you could do something like:
function startsWith(element) { return element.indexOf(this) === 0; } addressBook.filter(startsWith, wordToCompare);