Nodejs Array Index indexOfSmallestindexOfSmallest(k)

Here you can find the source of indexOfSmallestindexOfSmallest(k)

Method Source Code

/**//from   ww w .  j a v a2 s.  co m
 * Find the index of the smallest element in an  array
 */

Array.prototype.indexOfSmallest = function indexOfSmallest(k) {
  let lowest = 0;
  const a = this;

  for (let i = 1; i < a.length; i++) {
    if (k) {
      if (a[i][k] < a[lowest][k]) lowest = i;
    } else {
      if (a[i] < a[lowest]) lowest = i;
    }
  }
  return lowest;
};

Related

  1. indexOfObject(obj)
    Array.prototype.indexOfObject = function(obj) {
      for ( var i = 0, len = this.length; i < len; i++) {
        if (angular.equals(this[i], obj))
          return i;
      return -1;
    };
    
  2. indexOfObject(prop, val)
    Array.prototype.indexOfObject = function(prop, val) {
      function traverseObject(obj) {
        if(typeof(obj) === 'object') {
          for(var e in obj) {
            if(obj[prop] == val) {
              return true;
            } else {
              return traverseObject(obj[e]);
        return false;
      for(var i = 0; i < this.length; i++) {
        if(this[i] == val) {
          return i;
        } else if(traverseObject(this[i])) {
          return i;
      return -1;
    };
    
  3. indexOfObject(property, value)
    Array.prototype.indexOfObject = function(property, value) {
        for (var i = 0, len = this.length; i < len; i++) {
            if (this[i] !== null && this[i][property] === value) return i;
        return -1;
    
  4. indexOfObjectIdindexOfObjectId(element)
    Array.prototype.indexOfObjectId = function indexOfObjectId(element) {
        for (var i = 0, len = this.length; i < len; i++) {
            if (this[i].equals(element)) {
                return i;
        return -1;
    };
    
  5. indexOfSelect(filter)
    Array.prototype.indexOfSelect = function(filter)
      for (var i = 0; i< this.length; i++) {
        if(filter(this[i])){
          return i;
      return -1;