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

Discussion in 'Javascript' started by jmdolinger@earthlink.net, Nov 24, 2006.

  1. Guest

    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
     
    , Nov 24, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. The LoxFather

    C plus plus vs C Sharp

    The LoxFather, Aug 9, 2003, in forum: C++
    Replies:
    23
    Views:
    9,227
  2. claude uq
    Replies:
    5
    Views:
    363
    Phlip
    Dec 17, 2003
  3. dorayme
    Replies:
    6
    Views:
    1,791
    dorayme
    Jun 27, 2010
  4. RobG
    Replies:
    6
    Views:
    229
  5. Marc
    Replies:
    2
    Views:
    121
Loading...

Share This Page