Possible Duplicate:
How can I get the memory address of a JavaScript variable?
Is there a way, in javascript, to print the reference of an array?
What I want to do is to check if two arrays have the same reference, and it can be done like this post suggests: How to check if two vars have the same reference?
But is it possible to print the reference, if for instance I'm working with an array?
Example
var Array1=["hi"];
var Array2=["hello"];
var thesame = Array1==Array2;
the same value is false
.
But can I print he Array1 reference with somethink like window.alert(@Array1);
in javascript?
--UPDATE --
What I exactly want is the actual address space being referenced.
To get a list of duplicate objects in an array of objects with JavaScript, we can use the array methods. to get an array of value entries with the same id and put them into duplicates . To do this, we get the id s of the items with the same id by calling map to get the id s into their own array.
When you copy an object b = a both variables will point to the same address. This behavior is called copy by reference value. Strictly speaking in Ruby and JavaScript everything is copied by value. When it comes to objects though, the values happen to be the memory addresses of those objects.
For reference type like objects, == or === operators check its reference only. here a==b will be false as reference of both variables are different though their content are same. and if i check now a==b then it will be true , since reference of both variable are same now.
Javascript implementations are only standardised in so much as they follow the ECMA spec. The intricacies of memory storage could differ by browser, and are not made accessible to JS.
As far as your question of why is concerned: JS is a lightweight scripting language. It makes sense to delegate memory management and optimization tasks to the platform, whereas it would require unnecessary hoop jumping to expose an interface for this to you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With