Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
128
rated 0 times [  132] [ 4]  / answers: 1 / hits: 18486  / 14 Years ago, wed, february 2, 2011, 12:00:00

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>

More From » arrays

 Answers
206

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 });

[#93930] Tuesday, February 1, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
yulissamirandah

Total Points: 493
Total Questions: 115
Total Answers: 94

Location: Lebanon
Member since Sun, Aug 2, 2020
4 Years ago
yulissamirandah questions
Fri, Jun 17, 22, 00:00, 2 Years ago
Wed, Aug 26, 20, 00:00, 4 Years ago
Tue, Jan 28, 20, 00:00, 4 Years ago
Mon, Nov 11, 19, 00:00, 5 Years ago
;