[HashMap di JavaScript]
Bagaimana cara membuat array seperti di PHP, tapi di JavaScript?
Bisa loh, pake object.
*Cara 1:*
arr = new Object();
arr['hello'] = 'world';
arr['world'] = 'earth';
arr['earth'] = 'an array';
arr[0] = 1;
arr[1] = 2;
arr['an array'] = new Object();
arr['an array']['wow'] = 'wow an array';
arr['an array']['crazy'] = 'wow crazy';
arr['newarray'] = new Object();
arr['newarray']['a'] = new Object();
arr['newarray']['b'] = new Object();
arr['newarray']['a']['c'] = 'd';
*Cara 2:*
wow = {
'one': {
'ones' : '1s',
'twos' : '2s'
},
'two': {
'nested' : {
'nested!' : '!'
}
},
'three' : {
}
};
Lalu diprintnya gimana? Ya bikin sendiri fungsi rekursifnya.
Kalo mau lewat AJAX di-POST ato di-GET? Ya sila bikin sendiri juga
fungsi pengkode ke query stringnya...