spires Posted August 25, 2009 Share Posted August 25, 2009 Hi guys. I'm doing a a simple equation, all I want to do is add to value together. However, instead of adding the are concatenating. Both value are numeric so it should work fine, when I replace the variable with a static numeric number it works fine. but when I use the variable it keeps concatenating. Any ideas? My Code: var joinedProduct=productarray[1]+productarray[2]; alert(joinedProduct); productarray[1] = 60 productarray[2] = 60 output = 6060 not = 120 Thanks Quote Link to comment Share on other sites More sharing options...
haku Posted August 25, 2009 Share Posted August 25, 2009 They are both numeric, but that doesn't mean that javascript sees them as numbers. It is seeing them as text. Use this: var joinedProduct= Number(productarray[1]) + Number(productarray[2]); It should solve your problem. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.