Problems with plus or minus sign as key in a javascript hash?

J

jmdolinger

Hi all,

Has anyone ever seen the following Javascript problem (in IE). I'm
trying to set up a hash of rating values to integers (which I'll then
use to sort an array of ratings). It looks like this:

var ratingsTable = new Object();
ratingsTable["AAA"] = 0;
ratingsTable["AA+"] = 1;
ratingsTable["AA"] = 2;
ratingsTable["AA-"] = 3;
ratingsTable["A+"] = 4;
ratingsTable["A"] = 5;
ratingsTable["A-"] = 6;
....

However, any values that contain the "+" or "-" don't get added. I up
with a hash containing
AAA = 0, AA = 2, A = 5

This is something I've never come across in javascript before, but then
again I've never had to do it. A colleague has suggested preprocessing
the strings coming in for comparison so that "AA+" becomes "AAPlus"
That'll certainly work but is somewhat of a kluge. Is there some way
to escape the + or - sign so that these work as keys that are strings?


Am I going about this in the completely wrong way? Thanks, any help is
greatly appreciated!

Regards,
Jason
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top