I want to declare associative array in the argument of function in - is it possible??
this code it's not working..
<a href="javascript:functionName(new Array('cool'=>'Mustang','family'=>'Station'))">click</a>
that code is working - is it the only way?
<script>
var my_cars= new Array()
my_cars["cool"]="Mustang";
my_cars["family"]="Station";
</script>
<a href="javascript:functionName(my_cars)">click</a>
You're trying to using PHP syntax in Javascript.
You need to use Javascript syntax to create an object literal:
functionName({ cool: "Mustang", family: "Station" });
Don't use "new Array()" when all you want is an object with strings as property names:
var my_cars = {};
my_cars["cool"]="Mustang";
my_cars["family"]="Station";
or just
var my_cars = {
cool: 'Mustang', family: 'Station'
};
Arrays are intended to support integer-indexed properties, and they also maintain the "length" of the list of integer-indexed properties automatically (well, the "conceptual" length).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With