Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

print the handler/reference of an array (or object) in Javascript [duplicate]

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.

like image 947
Daniele B Avatar asked Dec 03 '12 14:12

Daniele B


People also ask

How do you get a list of duplicate objects in an array of objects with JavaScript?

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.

Is JavaScript copy by reference or value?

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.

How do I find the reference of an object?

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.


1 Answers

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.

like image 178
Asad Saeeduddin Avatar answered Oct 04 '22 17:10

Asad Saeeduddin