4

i have a problem with the each function.

HTML

<div id="d1" class="line1"></div>

JS

$(function() {


tt = new Array();
tt['id_32'] = new Array("32", "gudfgws", "htdfgss", "0", "gudfgdgfs", "0", "halder", "0");  
tt['id_35'] = new Array("35", "TVdfg.xml", "154", "Was läuft jetzt im TV", "0", "simpsons", "0");
tt['id_36'] = new Array("36", "Gddfge", "httdfg0", "155", "Idfgs", "0", "apple", "0");

   $.each(tt, function(key1,key2)
   {             
       $('#d1').append('-> '+key1+' - '+key2+' <br />');                 
  });

});

I dont get anything ... no error and no results. Can anybody tell me where the bug is?

Working example http://www.jsfiddle.net/V9Euk/558/

Thanks in advance! Peter

2 Answers 2

3

You're using named indexes with an array which doesn't work, you need tt to be an object instead, like this:

var tt = {};

Here's the updated/working version.

Sign up to request clarification or add additional context in comments.

Comments

0
$(function() {
    tt = {} //Object
    tt.id_32 = new Array("32", "gudfgws", "htdfgss", "0", "gudfgdgfs", "0", "halder", "0");  
    tt.id_35 = new Array("35", "TVdfg.xml", "154", "Was läuft jetzt im TV", "0", "simpsons", "0");
    tt.id_36 = new Array("36", "Gddfge", "httdfg0", "155", "Idfgs", "0", "apple", "0");

    $.each(tt,function(_key,_array){
       $.each(_array,function(value){
           $('#d1').append('-> '+_key+' - '+value+' <br />')
       });
    })
});

Give that a go for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.