arr[key] = value;
where key is a jQuery object and value is an array.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Associative arrays don’t really exist in JavaScript. However, you can achieve similar functionality using JavaScript objects:
To use an object as a key, you would have to do something like:
Using an object as a key sounds a bit weird, though. Are you sure you need to do this?
Update:
You can’t actually use an object as a key in JavaScript. The reason the above code appears to work is that, in the statement
b[a] = "Testing";, JavaScript convertsato a string viaa.toString(), which results in"[object Object]", and uses this string as the key. So our statement is actuallyb["[object Object]"] = "Testing";and our alert statement is exactly the same asalert(b["[object Object]"]);.Thanks to CMS for pointing this out in the comments!
Update 2:
Tim Down points out that his JavaScript library
jshashtableallows you use an object as a key.