Si noti che la sostituzione Array() è la chiave qui con i missing ')'
var array1 = {};
array1['one'] = new Object();
array1['one']['data'] = 'some text';
array1['one']['two'] = new Object();
array1['one']['two']['three'] = new Object();
array1['one']['two']['three']['data'] = 'some other text';
$.each(array1, function(key1, value1) {
$.each(value1['two']['three'], function(key1, value1) {
document.write('test');
});
});
e un altro modo di scrivere la stessa cosa: (piccolo tweek sulla scrittura per fare riferimento l'oggetto)
var array1 = {};
array1.one = new Object();
array1.one.data = 'some text';
array1.one.two = new Object();
array1.one.two.three = new Object();
array1.one.two.three.data = 'some other text';
$.each(array1, function(key1, value1) {
$.each(value1['two']['three'], function(key1, value1) {
document.write('test' + array1.one.data);
});
});
E, infine, con la deprecata new Object() sostituzione:
var array1 = {};
array1['one'] = {}
array1['one']['data'] = 'some text';
array1['one']['two'] = {};
array1['one']['two']['three'] = {};
array1['one']['two']['three']['data'] = 'some other text';
$.each(array1, function(key1, value1) {
$.each(value1['two']['three'], function(key1, value1) {
document.write('test');
});
});
EDIT: divertirsi un po 'di spirito h l'array, e perché si potrebbe avere le corde della dichiarazione oggetto come lo avete:
var array1 = {};
var fun="four";
array1.one = {};
array1.one.data = 'some text';
array1.one.two = {};
array1.one.two.three = {};
array1.one.two.three.data = 'some other text';
array1.one.two[fun] = {};
array1.one.two[fun].data=' howdy';
$.each(array1, function(key1, value1) {
$.each(value1.two.three, function(key1, value1) {
document.write('test'+array1.one.two[fun].data+ ":"+key1+":"+value1);
});
});
l'uscita del l'ultimo è: "test Howdy: Dati: qualche altro testo"
Quelli sono * * non ** Array che stai usando lì, ma Oggetti normali. Non usare 'new Array()' ma 'new Object()' (o semplicemente '{}' per un oggetto "vuoto"). – RoToRa