Here's an essential answer that requires the use of a certain library. In this case, I am utilizing lodash:
var text = ["Heather", "kfdjsalfjdai", "fdjafhjdksafh", "Heather", "Heather", "something"],
myName = "Heather";
var hits = _.filter(text, _.matches([myName]);
This may seem a bit counterintuitive at first, so let me explain what's going on. The `_.filter` function essentially does the same thing as `Array.prototype.filter`, but it's more efficient. Feel free to run your own tests below to see how it performs:
https://jsperf.com/array-filter-vs-lodash-filter-without-bias/2
The reason why lodash functions like `map`, `reduce`, and `filter` are faster is because they don't strictly adhere to the spec implementation.
To elaborate, the `_.filter` function takes two arguments: a collection (array or object) and a function that evaluates to true or false. If true, it will return the item.
The `_.matches` function is a handy tool that generates a function capable of comparing its argument against the contents of a specified collection.
You could achieve the same result in a slightly different manner:
var hits = _.filter(text, function(str) {
return str === myName
});
In lodash, we often create functions that essentially perform equality checks. `_.matches` simply streamlines the process by creating an equality check function for us.