Find vs For loop

Edit on GitHub

Setup

var a = [{
  "id": 1,
  "first_name": "Sara",
  "email": "[email protected]"
}, {
  "id": 2,
  "first_name": "Joe",
  "email": "[email protected]"
}, {
  "id": 3,
  "first_name": "Larry",
  "email": "[email protected]"
}, {
  "id": 4,
  "first_name": "Billy",
  "email": "[email protected]"
}, {
  "id": 5,
  "first_name": "Roy",
  "email": "[email protected]"
}, {
  "id": 6,
  "first_name": "Nicole",
  "email": "[email protected]"
}, {
  "id": 7,
  "first_name": "Mildred",
  "email": "[email protected]"
}, {
  "id": 8,
  "first_name": "Johnny",
  "email": "[email protected]"
}, {
  "id": 9,
  "first_name": "Susan",
  "email": "[email protected]"
}, {
  "id": 10,
  "first_name": "Jose",
  "email": "[email protected]"
}, {
  "id": 11,
  "first_name": "Harry",
  "email": "[email protected]"
}, {
  "id": 12,
  "first_name": "Nicole",
  "email": "[email protected]"
}, {
  "id": 13,
  "first_name": "Nicole",
  "email": "[email protected]"
}, {
  "id": 14,
  "first_name": "Carolyn",
  "email": "[email protected]"
}, {
  "id": 15,
  "first_name": "Betty",
  "email": "[email protected]"
}, {
  "id": 16,
  "first_name": "Carolyn",
  "email": "[email protected]"
}, {
  "id": 17,
  "first_name": "Russell",
  "email": "[email protected]"
}, {
  "id": 18,
  "first_name": "Chris",
  "email": "[email protected]"
}, {
  "id": 19,
  "first_name": "Heather",
  "email": "[email protected]"
}, {
  "id": 20,
  "first_name": "Billy",
  "email": "[email protected]"
}, {
  "id": 21,
  "first_name": "Carol",
  "email": "[email protected]"
}, {
  "id": 22,
  "first_name": "Harry",
  "email": "[email protected]"
}, {
  "id": 23,
  "first_name": "Rose",
  "email": "[email protected]"
}, {
  "id": 24,
  "first_name": "Sandra",
  "email": "[email protected]"
}, {
  "id": 25,
  "first_name": "Angela",
  "email": "[email protected]"
}, {
  "id": 26,
  "first_name": "Johnny",
  "email": "[email protected]"
}, {
  "id": 27,
  "first_name": "Gregory",
  "email": "[email protected]"
}, {
  "id": 28,
  "first_name": "Jean",
  "email": "[email protected]"
}, {
  "id": 29,
  "first_name": "Daniel",
  "email": "[email protected]"
}, {
  "id": 30,
  "first_name": "Janice",
  "email": "[email protected]"
}, {
  "id": 31,
  "first_name": "Kimberly",
  "email": "[email protected]"
}, {
  "id": 32,
  "first_name": "Heather",
  "email": "[email protected]"
}, {
  "id": 33,
  "first_name": "Chris",
  "email": "[email protected]"
}, {
  "id": 34,
  "first_name": "Sarah",
  "email": "[email protected]"
}, {
  "id": 35,
  "first_name": "Martin",
  "email": "[email protected]"
}, {
  "id": 36,
  "first_name": "Ralph",
  "email": "[email protected]"
}, {
  "id": 37,
  "first_name": "Roger",
  "email": "[email protected]"
}, {
  "id": 38,
  "first_name": "Lillian",
  "email": "[email protected]"
}, {
  "id": 39,
  "first_name": "Cynthia",
  "email": "[email protected]"
}, {
  "id": 40,
  "first_name": "Robin",
  "email": "[email protected]"
}, {
  "id": 41,
  "first_name": "Christine",
  "email": "[email protected]"
}, {
  "id": 42,
  "first_name": "Phyllis",
  "email": "[email protected]"
}, {
  "id": 43,
  "first_name": "Thomas",
  "email": "[email protected]"
}, {
  "id": 44,
  "first_name": "Joe",
  "email": "[email protected]"
}, {
  "id": 45,
  "first_name": "Rose",
  "email": "[email protected]"
}, {
  "id": 46,
  "first_name": "Helen",
  "email": "[email protected]"
}, {
  "id": 47,
  "first_name": "Melissa",
  "email": "[email protected]"
}, {
  "id": 48,
  "first_name": "Dorothy",
  "email": "[email protected]"
}, {
  "id": 49,
  "first_name": "Gary",
  "email": "[email protected]"
}, {
  "id": 50,
  "first_name": "Donna",
  "email": "[email protected]"
}, {
  "id": 51,
  "first_name": "Clarence",
  "email": "[email protected]"
}, {
  "id": 52,
  "first_name": "Anthony",
  "email": "[email protected]"
}, {
  "id": 53,
  "first_name": "Kathy",
  "email": "[email protected]"
}, {
  "id": 54,
  "first_name": "Sandra",
  "email": "[email protected]"
}, {
  "id": 55,
  "first_name": "Walter",
  "email": "[email protected]"
}, {
  "id": 56,
  "first_name": "Nancy",
  "email": "[email protected]"
}, {
  "id": 57,
  "first_name": "Rebecca",
  "email": "[email protected]"
}, {
  "id": 58,
  "first_name": "Willie",
  "email": "[email protected]"
}, {
  "id": 59,
  "first_name": "Cheryl",
  "email": "[email protected]"
}, {
  "id": 60,
  "first_name": "Jason",
  "email": "[email protected]"
}, {
  "id": 61,
  "first_name": "Amanda",
  "email": "[email protected]"
}, {
  "id": 62,
  "first_name": "Carol",
  "email": "[email protected]"
}, {
  "id": 63,
  "first_name": "Larry",
  "email": "[email protected]"
}, {
  "id": 64,
  "first_name": "Stephanie",
  "email": "[email protected]"
}, {
  "id": 65,
  "first_name": "Willie",
  "email": "[email protected]"
}, {
  "id": 66,
  "first_name": "Paul",
  "email": "[email protected]"
}, {
  "id": 67,
  "first_name": "Nicholas",
  "email": "[email protected]"
}, {
  "id": 68,
  "first_name": "Clarence",
  "email": "[email protected]"
}, {
  "id": 69,
  "first_name": "Emily",
  "email": "[email protected]"
}, {
  "id": 70,
  "first_name": "Joseph",
  "email": "[email protected]"
}, {
  "id": 71,
  "first_name": "Michael",
  "email": "[email protected]"
}, {
  "id": 72,
  "first_name": "Jimmy",
  "email": "[email protected]"
}, {
  "id": 73,
  "first_name": "John",
  "email": "[email protected]"
}, {
  "id": 74,
  "first_name": "Brandon",
  "email": "[email protected]"
}, {
  "id": 75,
  "first_name": "Joshua",
  "email": "[email protected]"
}, {
  "id": 76,
  "first_name": "Scott",
  "email": "[email protected]"
}, {
  "id": 77,
  "first_name": "Janet",
  "email": "[email protected]"
}, {
  "id": 78,
  "first_name": "Denise",
  "email": "[email protected]"
}, {
  "id": 79,
  "first_name": "Kathy",
  "email": "[email protected]"
}, {
  "id": 80,
  "first_name": "Patricia",
  "email": "[email protected]"
}, {
  "id": 81,
  "first_name": "Alice",
  "email": "[email protected]"
}, {
  "id": 82,
  "first_name": "Dennis",
  "email": "[email protected]"
}, {
  "id": 83,
  "first_name": "Kelly",
  "email": "[email protected]"
}, {
  "id": 84,
  "first_name": "Edward",
  "email": "[email protected]"
}, {
  "id": 85,
  "first_name": "Roy",
  "email": "[email protected]"
}, {
  "id": 86,
  "first_name": "Sandra",
  "email": "[email protected]"
}, {
  "id": 87,
  "first_name": "Jean",
  "email": "[email protected]"
}, {
  "id": 88,
  "first_name": "Mary",
  "email": "[email protected]"
}, {
  "id": 89,
  "first_name": "Joyce",
  "email": "[email protected]"
}, {
  "id": 90,
  "first_name": "Ashley",
  "email": "[email protected]"
}, {
  "id": 91,
  "first_name": "Anthony",
  "email": "[email protected]"
}, {
  "id": 92,
  "first_name": "Dorothy",
  "email": "[email protected]"
}, {
  "id": 93,
  "first_name": "Stephen",
  "email": "[email protected]"
}, {
  "id": 94,
  "first_name": "Janice",
  "email": "[email protected]"
}, {
  "id": 95,
  "first_name": "Christina",
  "email": "[email protected]"
}, {
  "id": 96,
  "first_name": "Anna",
  "email": "[email protected]"
}, {
  "id": 97,
  "first_name": "Jerry",
  "email": "[email protected]"
}, {
  "id": 98,
  "first_name": "Tammy",
  "email": "[email protected]"
}, {
  "id": 99,
  "first_name": "Arthur",
  "email": "[email protected]"
}, {
  "id": 100,
  "first_name": "Robin",
  "email": "[email protected]"
}];

Tests

  • Find

    var x = a.find(function(e){return e.first_name==='Amanda'})
  • For loop

    var al = a.length-1,x, i=0;
    while(i<a && a[i].first_name!=='Amanda'){
      i++;
    }
    x = a[i];