Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i get a object's name into string form using JS? [duplicate]

For example,I have a object here

var obj = {a:1,b:2,c:3}

how can i get obj'name to a String "obj"?

like image 376
nice Avatar asked May 17 '26 03:05

nice


1 Answers

You can't. An object may be named by any number of variables, e.g.

var obj = {a:1,b:2,c:3};
var obj2 = obj;
var otherobj = obj2;

All these variables reference the same object -- it doesn't have a specific name.

like image 103
Barmar Avatar answered May 19 '26 16:05

Barmar