I want to check whether or not an object exists in an array given its key (key is not unique).The object takes the form:class item {    key: string,    value: (string|int|boolean),    id: Guid}And this._items is an item array.First approach is simply filtering the array and checking its length:has(key) {    return this._items.filter(item => item.key === key).length > 0;}Then a for loop that terminates when exists is true.has(key) {    let exists = false;    for (let i = 0; i < this._items.length && !exists; i++) {        exists = this._items[i].key === key;    }    return exists;}One more take on it, this.keys() returns an array of unique item keys:has(key) {    return this.keys().toString().match(new RegExp(key, 'ig')).length > 0;}The first one is cleaner / more readable but iterates over every item in the array. The second one doesn't read quite as well but only iterates over as many items as it needs to.Until it needs to be optimized, is this just a preference/coding-style thing?
Checking whether any item in an array has a desired value for a key
javascript;performance;comparative review