How to use the findIndex function from underscore

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

137
138
139
140
141
142
143
144
145
// posts are simply "\n". Remove all the "\r"s so that
// everything looks like we expect.
data = data.replace(/\r/g, '');
var lines = data.lines();
// Extract the metadata
var metadataEnds = _.findIndex(lines, function (line) {
	 return line.trim().length === 0; 
});
metadataEnds = metadataEnds === -1 ? lines.length : metadataEnds;
fork icon55
star icon265
watch icon27

+ 38 other calls in file

4928
4929
4930
4931
4932
4933
4934
4935
4936
4937

// Return the first value which passes a truth test. Aliased as `detect`.
_.find = _.detect = function(obj, predicate, context) {
  var key;
  if (isArrayLike(obj)) {
    key = _.findIndex(obj, predicate, context);
  } else {
    key = _.findKey(obj, predicate, context);
  }
  if (key !== void 0 && key !== -1) return obj[key];
fork icon0
star icon2
watch icon0

33
34
35
36
37
38
39
40
41
42
        boardId: undefined,
        boardType: undefined,
        userId: undefined
    }

const keyRecordI = _.findIndex(records, (curRecord) => {
    const userEmail = curRecord.expand.userId.email
    const userPhone = curRecord.expand.userId.phone

    const curRecordUserContact = (curRecord.expand.userId === 'email') ? userEmail : userPhone
fork icon0
star icon0
watch icon1