Array#find() vs While vs json.stringify().split

Edit on GitHub

Setup

var a = [{
  "id": 1,
  "first_name": "Janice",
  "email": "[email protected]"
}, {
  "id": 2,
  "first_name": "Kevin",
  "email": "[email protected]"
}, {
  "id": 3,
  "first_name": "Aaron",
  "email": "[email protected]"
}, {
  "id": 4,
  "first_name": "Steve",
  "email": "[email protected]"
}, {
  "id": 5,
  "first_name": "Stephen",
  "email": "[email protected]"
}, {
  "id": 6,
  "first_name": "Denise",
  "email": "[email protected]"
}, {
  "id": 7,
  "first_name": "Anna",
  "email": "[email protected]"
}, {
  "id": 8,
  "first_name": "Billy",
  "email": "[email protected]"
}, {
  "id": 9,
  "first_name": "Jane",
  "email": "[email protected]"
}, {
  "id": 10,
  "first_name": "Janice",
  "email": "[email protected]"
}, {
  "id": 11,
  "first_name": "Jason",
  "email": "[email protected]"
}, {
  "id": 12,
  "first_name": "Betty",
  "email": "[email protected]"
}, {
  "id": 13,
  "first_name": "Patrick",
  "email": "[email protected]"
}, {
  "id": 14,
  "first_name": "Ashley",
  "email": "[email protected]"
}, {
  "id": 15,
  "first_name": "Henry",
  "email": "[email protected]"
}, {
  "id": 16,
  "first_name": "Henry",
  "email": "[email protected]"
}, {
  "id": 17,
  "first_name": "Kevin",
  "email": "[email protected]"
}, {
  "id": 18,
  "first_name": "Jeremy",
  "email": "[email protected]"
}, {
  "id": 19,
  "first_name": "Chris",
  "email": "[email protected]"
}, {
  "id": 20,
  "first_name": "Sean",
  "email": "[email protected]"
}, {
  "id": 21,
  "first_name": "Ernest",
  "email": "[email protected]"
}, {
  "id": 22,
  "first_name": "Jesse",
  "email": "[email protected]"
}, {
  "id": 23,
  "first_name": "Dorothy",
  "email": "[email protected]"
}, {
  "id": 24,
  "first_name": "Juan",
  "email": "[email protected]"
}, {
  "id": 25,
  "first_name": "Deborah",
  "email": "[email protected]"
}, {
  "id": 26,
  "first_name": "Jessica",
  "email": "[email protected]"
}, {
  "id": 27,
  "first_name": "Wanda",
  "email": "[email protected]"
}, {
  "id": 28,
  "first_name": "Patrick",
  "email": "[email protected]"
}, {
  "id": 29,
  "first_name": "Gregory",
  "email": "[email protected]"
}, {
  "id": 30,
  "first_name": "Kimberly",
  "email": "[email protected]"
}, {
  "id": 31,
  "first_name": "Irene",
  "email": "[email protected]"
}, {
  "id": 32,
  "first_name": "Dorothy",
  "email": "[email protected]"
}, {
  "id": 33,
  "first_name": "Jeremy",
  "email": "[email protected]"
}, {
  "id": 34,
  "first_name": "Debra",
  "email": "[email protected]"
}, {
  "id": 35,
  "first_name": "Barbara",
  "email": "[email protected]"
}, {
  "id": 36,
  "first_name": "Bonnie",
  "email": "[email protected]"
}, {
  "id": 37,
  "first_name": "Frances",
  "email": "[email protected]"
}, {
  "id": 38,
  "first_name": "Elizabeth",
  "email": "[email protected]"
}, {
  "id": 39,
  "first_name": "Jennifer",
  "email": "[email protected]"
}, {
  "id": 40,
  "first_name": "Theresa",
  "email": "[email protected]"
}, {
  "id": 41,
  "first_name": "Rachel",
  "email": "[email protected]"
}, {
  "id": 42,
  "first_name": "Lisa",
  "email": "[email protected]"
}, {
  "id": 43,
  "first_name": "Kimberly",
  "email": "[email protected]"
}, {
  "id": 44,
  "first_name": "Chris",
  "email": "[email protected]"
}, {
  "id": 45,
  "first_name": "Antonio",
  "email": "[email protected]"
}, {
  "id": 46,
  "first_name": "Irene",
  "email": "[email protected]"
}, {
  "id": 47,
  "first_name": "Raymond",
  "email": "[email protected]"
}, {
  "id": 48,
  "first_name": "Janice",
  "email": "[email protected]"
}, {
  "id": 49,
  "first_name": "Charles",
  "email": "[email protected]"
}, {
  "id": 50,
  "first_name": "Wayne",
  "email": "[email protected]"
}, {
  "id": 51,
  "first_name": "Janet",
  "email": "[email protected]"
}, {
  "id": 52,
  "first_name": "Jennifer",
  "email": "[email protected]"
}, {
  "id": 53,
  "first_name": "Andrea",
  "email": "[email protected]"
}, {
  "id": 54,
  "first_name": "Gary",
  "email": "[email protected]"
}, {
  "id": 55,
  "first_name": "Fred",
  "email": "[email protected]"
}, {
  "id": 56,
  "first_name": "Peter",
  "email": "[email protected]"
}, {
  "id": 57,
  "first_name": "Diana",
  "email": "[email protected]"
}, {
  "id": 58,
  "first_name": "Pamela",
  "email": "[email protected]"
}, {
  "id": 59,
  "first_name": "Elizabeth",
  "email": "[email protected]"
}, {
  "id": 60,
  "first_name": "Jose",
  "email": "[email protected]"
}, {
  "id": 61,
  "first_name": "Ernest",
  "email": "[email protected]"
}, {
  "id": 62,
  "first_name": "Jacqueline",
  "email": "[email protected]"
}, {
  "id": 63,
  "first_name": "Nancy",
  "email": "[email protected]"
}, {
  "id": 64,
  "first_name": "Ronald",
  "email": "[email protected]"
}, {
  "id": 65,
  "first_name": "Todd",
  "email": "[email protected]"
}, {
  "id": 66,
  "first_name": "Charles",
  "email": "[email protected]"
}, {
  "id": 67,
  "first_name": "Ruby",
  "email": "[email protected]"
}, {
  "id": 68,
  "first_name": "Todd",
  "email": "[email protected]"
}, {
  "id": 69,
  "first_name": "Gerald",
  "email": "[email protected]"
}, {
  "id": 70,
  "first_name": "Ralph",
  "email": "[email protected]"
}, {
  "id": 71,
  "first_name": "Brandon",
  "email": "[email protected]"
}, {
  "id": 72,
  "first_name": "Heather",
  "email": "[email protected]"
}, {
  "id": 73,
  "first_name": "Lisa",
  "email": "[email protected]"
}, {
  "id": 74,
  "first_name": "Ann",
  "email": "[email protected]"
}, {
  "id": 75,
  "first_name": "Sarah",
  "email": "[email protected]"
}, {
  "id": 76,
  "first_name": "Carol",
  "email": "[email protected]"
}, {
  "id": 77,
  "first_name": "Jeremy",
  "email": "[email protected]"
}, {
  "id": 78,
  "first_name": "Teresa",
  "email": "[email protected]"
}, {
  "id": 79,
  "first_name": "Helen",
  "email": "[email protected]"
}, {
  "id": 80,
  "first_name": "Carlos",
  "email": "[email protected]"
}, {
  "id": 81,
  "first_name": "Bruce",
  "email": "[email protected]"
}, {
  "id": 82,
  "first_name": "Jason",
  "email": "[email protected]"
}, {
  "id": 83,
  "first_name": "Larry",
  "email": "[email protected]"
}, {
  "id": 84,
  "first_name": "Dorothy",
  "email": "[email protected]"
}, {
  "id": 85,
  "first_name": "Andrea",
  "email": "[email protected]"
}, {
  "id": 86,
  "first_name": "Stephen",
  "email": "[email protected]"
}, {
  "id": 87,
  "first_name": "Craig",
  "email": "[email protected]"
}, {
  "id": 88,
  "first_name": "Ronald",
  "email": "[email protected]"
}, {
  "id": 89,
  "first_name": "David",
  "email": "[email protected]"
}, {
  "id": 90,
  "first_name": "Jesse",
  "email": "[email protected]"
}, {
  "id": 91,
  "first_name": "Alice",
  "email": "[email protected]"
}, {
  "id": 92,
  "first_name": "Phillip",
  "email": "[email protected]"
}, {
  "id": 93,
  "first_name": "Marilyn",
  "email": "[email protected]"
}, {
  "id": 94,
  "first_name": "Alice",
  "email": "[email protected]"
}, {
  "id": 95,
  "first_name": "Jeffrey",
  "email": "[email protected]"
}, {
  "id": 96,
  "first_name": "Willie",
  "email": "[email protected]"
}, {
  "id": 97,
  "first_name": "Harold",
  "email": "[email protected]"
}, {
  "id": 98,
  "first_name": "Philip",
  "email": "[email protected]"
}, {
  "id": 99,
  "first_name": "Robin",
  "email": "[email protected]"
}, {
  "id": 100,
  "first_name": "Wayne",
  "email": "[email protected]"
}];

Tests

  • Array#find()

    a.find(function(e){return e.id===77})
  • While

    var l = a.length, x, i=0;
    while(i<l && a[i].id!==77){i++}
    x = a[i]
  • json.stringify().split

    a[JSON.stringify(a).split('"id":77')[0].split("},{").length-1]