Nodejs Utililty Methods Array Exist

List of utility methods to do Array Exist

Description

The list of methods to do Array Exist are organized into topic(s).

Method

exists(func)
Array.prototype.exists = function(func) {
  for (var i = 0; i < this.length; i++)
    if (func(this[i]))
      return true;
  return false;
};
exists(param, value)
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;
existsByKey(key, val)
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;