I have an array, inside this I have objects. I need to work with this and need to access to the object data.
Here is a sample of this array:
var result <-
(16)array […]
0:object {…}"myobjectname1": {…} style_name: "border-top-right-radius"
style_unit: "px"
style_value: "0"
1:object {…}"myobjectname2": {…} style_name: "border-bottom-right-radius"
style_unit: "px"
style_value: "0"
2:object { "myobjectname3": {…} }
3:object { "myobjectname4": {…} }
4:object { "myobjectname5": {…} }
...
I want to access directly to the different objects by the objectname
Example alert("result.myobjectname1.style_name");
It seem that this could not work, because I don't access the array by the index in this case [0]!?
I don't know this index, it could be different every time.
Is there a way, to directly access the objects by the objectname or in which way, I have to create a array/object that it works?
In php I will do it with a simple array, in JavaScript its not possible because my index is alphanumeric.
UPDATE
This is the way i create the datas in a each-loop
var match=new Array();
each(...)
{
...
var r = null;
r={ [myobjectname_from_variable] : { 'style_name': res_stylename,
'style_value': res_stylevalue,
'style_unit' : elem_styleunit} };
match.push(r);
...
}
Important: The value of myobjectname_from_variable is the same as res_stylename and it contains something like "border-top-right-radius"
Here we have to think about, how i can call this in javascript. For example
object.border-top-right-radius.style_value
wont breack and returns a error of undefined "right"...
border-top-right-radiusand it's throwing an error about "right" being undefined, then it's something we aren't looking at. From what we've seen so far, you have objects that are indexed by style names. That particular error might be in how yourres_stylevalueis being set, since nothing appears to adjust for a "right" property explicitly.