Associative array in Javascript
Jun 14th, 2008
<script type="text/javascript">
var salesPerson = { "firstName": "crockford",
"lastName": "Javascript Object Notation(JSON)",
"address": "Bangalore",
"phoneNumbers": [
"22222222",
"9000000000" ]
};
key = '';
value1 = '';
for (i in salesPerson)
{
key += i + ' ';
value1 += i + ': ' + eval ( '(' + 'salesPerson.' + i + ')') + "\n";
}
alert(key);
alert(value1);
alert(salesPerson.address);
alert(salesPerson.phoneNumbers);
</script>
Next: Associative Array in JavaScript
Possibly Related posts:
Here is something similar to associative array in JavaScript. But as it is not an associative array, so you cannot use JavaScript array methods. It is JSON style Object representation.