Sorry about the shoddy title of this question - I really can't describe the problem any more succinctly!
I can't figure out what's happening in my code! I have an object which looks like this:
var fruits = {name: "bananas", quantity: "3"}
And an quantity input field (#qty
) whose value is (let's say) 2.
console.log(fruits);
alert(fruits[0].quantity); //outputs 3
fruits[0].quantity = Number(fruits[0].quantity) + Number($("#qty").val());
alert(fruits[0].quantity); //outputs 5
The problem is that after all of this runs, when I go into the console to inspect the output of console.log(fruits);
, the console shows {name: "bananas", quantity: 5}
.
P.S. Notice the added quantity and lack of quotation marks!
Any ideas what's happening?