How to use the findIndex function from lodash

Find comprehensive JavaScript lodash.findIndex code examples handpicked from public code repositorys.

5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
*   { 'name': 'barney',  'age': 36, 'blocked': false },
*   { 'name': 'fred',    'age': 40, 'blocked': true },
*   { 'name': 'pebbles', 'age': 1,  'blocked': false }
* ];
*
* _.findIndex(characters, function(chr) {
*   return chr.age < 20;
* });
* // => 2
*
fork icon73
star icon711
watch icon29

+ 5 other calls in file

114
115
116
117
118
119
120
121
122
123
module.exports.falsey              = _.falsey;
module.exports.falseyAll           = _.falseyAll;
module.exports.fill                = _.fill;
module.exports.filter              = _.filter;
module.exports.find                = _.find;
module.exports.findIndex           = _.findIndex;
module.exports.findKey             = _.findKey;
module.exports.findLast            = _.findLast;
module.exports.findLastIndex       = _.findLastIndex;
module.exports.findLastKey         = _.findLastKey;
fork icon19
star icon122
watch icon0

+ 92 other calls in file

352
353
354
355
356
357
358
359
360
361
}

// UPDATE CHANGELOG CONTENTS

const lines = chglog.replace(/\r/g, '').split('\n')
let firstVersionLine = _.findIndex(lines, l => l.startsWith('## '))

if (firstVersionLine >= 0 && lines[firstVersionLine].startsWith(`## [${latestTag.name}`)) {
  return core.notice('This version already exists in the CHANGELOG! No change will be made to the CHANGELOG.')
}
fork icon22
star icon49
watch icon0

30
31
32
33
34
35
36
37
38
39
function* explainInvalid(values, predicates, via) {
    if (values.length !== predicates.length) return;

    const pairs = _.zip(predicates, values);
    const isInvalid = _.negate(_.spread(isValid));
    const index = _.findIndex(pairs, isInvalid);
    if (index !== -1) {
        const [spec, val] = pairs[index];
        yield* firstProblem(spec, val, {path: [index], via, _in: [index]});
    }
fork icon1
star icon12
watch icon2

+ 11 other calls in file

539
540
541
542
543
544
545
546
547
548
  return (!field.editPermission && !field.viewPermission) ||
    (field.editPermission && self.apos.permission.can(req, field.editPermission.action, field.editPermission.type)) ||
    (field.viewPermission && self.apos.permission.can(req, field.viewPermission.action, field.viewPermission.type)) ||
    false;
});
const typeIndex = _.findIndex(schema, { name: 'type' });
if (typeIndex !== -1) {
  // This option exists so that the
  // @apostrophecms/option-overrides and @apostrophecms/workflow modules,
  // if present, can be used together to disable various types based
fork icon540
star icon0
watch icon0

61
62
63
64
65
66
67
68
69
70

let newIndex = index
if (index === undefined) {
  if (item.split("/").length === 2) {
    // if file in subcollection, get index of first file in subcollection
    newIndex = _.findIndex(
      content.collections[collectionName].order,
      (f) => f.split("/")[0] === item.split("/")[0]
    )
    if (newIndex === -1) newIndex = 0
fork icon0
star icon3
watch icon2

+ 7 other calls in file

103
104
105
106
107
108
109
110
111
112
);
// Peek at the next path to check the right child next
const nextPath = _.head(remainingPaths);
assertNotNull(nextPath, 'No more remaining paths, but expecting one of '
  + JSON.stringify(remainingChildren.map(c => c.toObj())));
const nextChildIndex = _.findIndex(remainingChildren, (node) =>
  _.isEqual(nextPath, curStack.concat([node.vertex]))
);
assertNotEqual(-1, nextChildIndex,
  `The following path is not valid at this point: ${JSON.stringify(nextPath)}
fork icon808
star icon0
watch icon340

128
129
130
131
132
133
134
135
136
137
for (let i = 0, j = friends.length; i < j; i++) {
  const friend = friends[i];

  console.log(i, friends.length - 1);

  const index = _.findIndex(roomId, { id: friend });

  let item = {};

  if (index >= 0) {
fork icon48
star icon185
watch icon11

227
228
229
230
231
232
233
234
235
236

// update challenge object
const newAttachments = _.get(challenge, "attachments", []);
try {
  newAttachments.splice(
    _.findIndex(newAttachments, (a) => a.id === attachmentId),
    1
  );
  await challengeService.partiallyUpdateChallenge(currentUser, challengeId, {
    attachments: newAttachments,
fork icon44
star icon17
watch icon25

119
120
121
122
123
124
125
126
127
f.group = g;

// push the field to the new schema, if it is a
// duplicate due to subclasses pushing more
// groupings, remove the earlier instance
let fIndex = _.findIndex(newSchema, { name: field });
if (fIndex !== -1) {
  newSchema.splice(fIndex, 1);
}
fork icon540
star icon0
watch icon125

+ 11 other calls in file

460
461
462
463
464
465
466
467
468
469
  prompts = prompts.filter(function (obj) {
    return (options.exclude.indexOf(obj.name) === -1);
  });
}
if (options && options.minVersion) {
  var defaultMinVersion = _.findIndex(prompts, {
    name: 'minVersion'
  });
  if (defaultMinVersion) {
    prompts[defaultMinVersion] = options.minVersion;
fork icon2
star icon5
watch icon7

2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
    negeri: all[i].negeri,
    username: all[i].user_name,
  };
  allData.push(location);
}
const num = _.findIndex(allData, { negeri: '-' });
allData.splice(num, 1);
const negeri = _.uniqBy(allData, 'negeri');
const daerah = _.uniqBy(allData, 'daerah');
const username = _.uniqBy(allData, 'username');
fork icon1
star icon4
watch icon0

36
37
38
39
40
41
42
43
44
45
46
47
48
console.log(fill); // => ['a', 'a', 'a']


const fillWith = _.fill(Array(3), 2);
console.log(fillWith); // => [2, 2, 2]


const findIndex = _.findIndex([1, 2, 3, 4], n => n % 2 === 1);
console.log(findIndex); // => 0


const findLastIndex = _.findLastIndex([1, 2, 3, 4], n => n % 2 === 1);
console.log(findLastIndex); // => 2
fork icon0
star icon4
watch icon0

+ 15 other calls in file

371
372
373
374
375
376
377
378
379
380
            transponder
        });
        sendToAllMessage('new-lap-update', newLap);
    }
} else if (gate?.type === 'GATE') {
    const inxCurrGate = _.findIndex(gates, ['_id', gate._id]);
    let typeLap = 'HIDDEN';
    let timeLap = undefined;
    if (
        (inxCurrGate === 0 && !this.lastTimeGates?.[membersGroup._id]?.[gate._id]) || //first gate
fork icon1
star icon1
watch icon1

+ 16 other calls in file

10
11
12
13
14
15
16
17
18
19
20
var ldapToUser = function (ldapUser, user, next) {
    var data = _.clone(user || {});
    
    data.admin =
        _.findIndex(ldapUser._groups, group_test) > -1 ||
        _.findIndex(ldapUser.memberOf, member_test) > -1;
    data.active = true;


    // copy attributes from the ldap user to the konga user using the ldapAttrMap
    for (var userAttr in ldapAttrMap) {
fork icon0
star icon1
watch icon1

+ 13 other calls in file

226
227
228
229
230
231
232
233
234
    enable.push(feature);
  }
}

function anyEnabled (features) {
  return _.findIndex(features, function(feature) {
    return enable.indexOf(feature) > -1;
  }) > -1;
}
fork icon0
star icon1
watch icon1

+ 7 other calls in file

575
576
577
578
579
580
581
582
583
584

//Are we doing anything with a comment?
else if(req.body.commentID)
{
  console.log("We have a comment action");
  var commentIndex = _.findIndex(user.feedAction[feedIndex].comments, function(o) { return o.comment == req.body.commentID; });

  //no comment in this post-actions yet
  if(commentIndex==-1)
  {
fork icon0
star icon0
watch icon1

+ 423 other calls in file

50
51
52
53
54
55
56
57
58
59
60
    return obj._id || obj.id || obj.name || obj.operationId || '$$index:' + index;
  }
});


function getCacheIndex(url) {
  return _.findIndex(httpCache.cache,function(e){
    return e.url === url;
  });
}

fork icon0
star icon0
watch icon5

+ 3 other calls in file

219
220
221
222
223
224
225
226
227
228
const now = new Date().toISOString();
const configToSave = this.fromRawToS3Object(configToUpdate, { updatedBy: by, updatedAt: now });
const configsToSave = existingConfigs || [];

// We need to preserve order of configs in the array so replace new one at correct index
const idxOfConfig = _.findIndex(existingConfigs, existingConfig);
configsToSave[idxOfConfig] = configToSave;

await s3Service.api
  .putObject({
fork icon0
star icon0
watch icon1

283
284
285
286
287
288
289
290
291
292
/** @inheritdoc */
async deleteEdge(id) {
    if (Utils.isEmpty(id)) {
        throw new Error(errors.isNil("id", "JsonGraphStore.deleteEdge"));
    }
    const index = _.findIndex(this.#edges, {id});
    if (index > -1) {
        this.#edges.splice(index, 1);
    }
}
fork icon0
star icon0
watch icon1

+ 59 other calls in file

Other functions in lodash

Sorted by popularity

function icon

lodash.get is the most popular function in lodash (7670 examples)