0

I'm not a Javascript person, but have inherited the joys. So far so good.

My javascript object, in firebug, looks like this

enter image description here

This shows that the array sss has 4 items in the array (0,1,2 and 3).

The complication comes when I expand one of these elements, I see

enter image description here

From my own tests these are not arrays. They are just treated as objects (or so it seems).

Within each DataItem, there is an object, you can just make it out called lzabel. Each DataItem has this value. I need to read the values within a for loop.

So, I would have hoped to use

for (var i = 0; i < sss[0];i++) { var z = sss[0][i]; //This is never executed } 

but no! No error, but the loop's content is never executed (as if sss[0] has no items).

How do I loop through like this?

for (var i = 0; i < sss[0];i++) { var z = sss[0][i]["lzabel"]; } 

EDIT

I added the following code

var t1 = sss.length; var t2 = sss[0].length; 

Firebug reports t1 = 4, and t2 as undefined.

3
  • Loop over the object's properties? Commented Feb 20, 2014 at 11:58
  • "Due to signing various non-disclosure agreements" - irrelevant. we don't need the actual code. any minimal code which reproduces the problem does the job. Commented Feb 20, 2014 at 11:58
  • Actually, I was talking about the screen shots being cut in such a way, and my comment was only to be polite! Commented Feb 20, 2014 at 12:00

3 Answers 3

1

To get Izabel ...

var sssData = sss[0]; // FYI: sss[0].length won't work because it's an object not an array for (x in sssData) { var dataItem = sssData[x]; console.log( dataItem.Izabel ); // one way to get Izabel property value console.log( dataItem["Izabel"] ) // two ways to get Izabel property value } 
Sign up to request clarification or add additional context in comments.

Comments

0

You should be able to loop like this:

for (i in sss[0]) { var z = sss[0][i]; } 

1 Comment

i is undefined (although it does now execute in the loop)!
0

Something like this?

for(i=0;i<sss.length;i++){ for(j=1;j<parseInt(Object.keys(sss[i]).length)+1;j++){ console.log(sss[i]["DataItem"+j].Izabel); } } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.