Javascript Array existsByKey(key, val)
/*/*from ww w .jav a 2s . com*/ * Utility Extension to look into an array * of objects by key to determine if it exists already */ Array.prototype.existsByKey = function(key, val) { var exists = this.map(function(obj) { return obj[key] }).indexOf(val) != -1; console.log('Does \'' + val + '\' exist? ' + exists); return exists; }