I have an object and some of its elements are object too. How can I make my variable just one object?
I mean I have a variable that has elements:
- name
- type
type is an object that has field:
- name
So I one that:
- name
- type.name (not as an object just another variable as like name)
PS:
When I inspect my variable with Firebug:
name
"fsfaf"
password
"242342425"
name
"XXX"
type
Object { name="sds"}
name
"sfs"
Let’s assume that I hold it with a variable myVariable. I want to do something like that:
var newVariable = somefunction(myVariable);
so my newVariable should be like that:
name
"fsfaf"
password
"242342425"
name
"XXX"
type.name
"sds"
name
"sfs"
I edited my answer too. Here’s a way to do what you want:
However, this way you cannot access newVar.type.name, you can access newVar[‘type.name’], which I guess is OK for what you want to accomplish…
P.S. Test extensively before applying to live projects, etc. I imagine a lot of things can go wrong, depending on the objects that you’re using. There should be no problem to use it in the situation you want though