I'm trying to test a set of some given variables. To organize the set, I'm adding the variables as keys to an object.
I think I'm on the right track with dynamically adding the key in accordance to the variable name. How can I ensure that each key's value corresponds to the value of the original given number?
example:
var num1 = 43;
var num2 = 597;
var num3 = 5662682;
I'd like for my object to basically come out like this:
{num1: 43, num2: 597, num3: 5662682}
I've tried:
function makeObj () {
var obj = {};
for (var i = 1; i <= 3; i++) {
obj["num" + i] = "num" + i;
}
return obj;
}
but obviously, does not reference the variable. it stores a useless string.
{ num1: 'num1', num2: 'num2', num3: 'num3' }
how would I get the value of the said variable (num1, num2, num3) to be the value of the key of the same name, inside of my object?
I should also add, I'm looking to do this with standard Javascript and/or prototyping. No libraries or anything like that.