-3

How to iterate over this kind of Json object in Prototype Js ( not Jquery)

There are also sub objects with value indexs

I want to populate multi select box with given values.

data = object(
    0 => object(
        'label' = > 'test1',
        'value' = > 1
    ),
    1 => object(
        'label' = > 'test1',
        'value' = >
        0 = > object(
            'label' = > 'sub testing1',
            'value' = > 1
        ),
        1 = > object(
            'label' = > 'sub testing2',
            'value' = > 1
        ),
    ),
    3 = > object(
        'label' = > 'test3',
        'value' = >
        0 = > object(
            'label' = > 'sub testing - test 3',
            'value' = > 33
        ),
    )
)

1 Answers1

1

I haven't used Prototype in a while but try this:

data.each(function(i){
    console.log(i.label); // or whatever you need to do
});
John Conde
  • 217,595
  • 99
  • 455
  • 496