Adding a JavaScript Object to Multiple Arrays

I have the following JavaScripts objects:

var foo = {"foofoo":value}; var bar = {"barbar":value2}; //and so on 

these objects will be added to several arrays:

 var container = [foo, bar, baz, etc]; var container2 = [foo, bar, glob, etc]; //and so on, for lots of containers. 

If I have many objects (e.g. foo) that will be placed in these arrays, would it be useful to use some hashcode table and store the objects using some UID? Or is the JavaScript following the link giving me this function already?

http://www.timdown.co.uk/jshashtable/ seems to provide such a function.

Sorry, but my JavaScript knowledge is not too complete.

Edit: I assume another way to re-express this question as a whole is is there any case where a hash table is useful for a language (like JavaScript) that passes objects by reference?

+4
source share
2 answers

Javascript objects are always passed by reference; it is impossible to inadvertently create a copy.

You have nothing to worry about.

+7
source

You can easily verify this by modifying container[0].foofoo and then reading it with container2[0].foofoo .

It will show you that the value has changed, which means that JavaScript uses object references.

0
source

Source: https://habr.com/ru/post/1415035/


All Articles