Here you can find the source of existsByKey(key, val)
/*//from w w w . ja v a2s . co m * 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; }
Array.prototype.exists = function(func) { for (var i = 0; i < this.length; i++) if (func(this[i])) return true; return false; };
const DEGREE_TO_RAD = Math.PI / 180 function max(a, b) { return a > b ? a : b; function rand(min, max) { if (min > max) return rand(max, min); if (min == max) return min; return min + parseInt(Math.random() * (max - min + 1)); Math.getUniqueNumber = function() { function s4() { return Math.floor((1 + Math.random()) * 0x10000) .toString(16) .substring(1); return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); Array.prototype.exists = function(param, value) { var found = -1; this.forEach(function(e, i) { if (typeof e[param] != 'undefined') { if (e[param] == value) { found = i; }) return found;