Nodejs Array Exist exists(func)

Here you can find the source of exists(func)

Method Source Code

Array.prototype.exists = function(func) {
   for (var i = 0; i < this.length; i++)
      if (func(this[i]))
         return true;
   return false;/*  ww  w  . j ava 2 s.  c o m*/
};

Related

  1. 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;
    
  2. 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;