2

I have a huge list of objects (e.g. I call them messages). Every message contains an array (e.g. I name them user) with 2, 3 or 4 strings (userids).

If I loop trough all messages I want to check in every message whence a userid is in the array or not. At which count of items in the array it would be faster to use an associative array² instead of a normal array¹ (regardless the time for creating the associative array)?

Certainly it takes time to create a hash (I think the associative array uses it), so I think an array with two items will be faster to loop...

Here is example one:

messages: {
  name: "msg1"
  users:[
    "1256",
    "1456"
  ]
}

Here is example two:

messages: {
  name: "msg1"
  users:{
    "1256": true,
    "1456": true
  }
}
Biber
  • 709
  • 6
  • 19
  • There's no such thing as "associative arrays" in Javascript. Those things are called *objects.* Also, you could and should **benchmark** it to optimise for **your use case**. – deceze Feb 06 '17 at 14:59
  • In my opinion, the first example is the best approach to this. – ibrahim mahrir Feb 06 '17 at 23:08

0 Answers0