-3
var i = "test";
var test1 = {
    test: 3,
    b: 3
};
console.log(test1.i);

Sorry if it's a simple answer, I am still learning.

var i is looping to something different every few seconds and var i will always be something on test1.

2 Answers2

1

Do it this way:

var test1 = {
    test : 3
};
console.log(test1[i])
LFF
  • 228
  • 1
  • 4
1

If you are trying to retrieve a property of an object you can use the . notation, or the [] notation

var test1 = {
    test: 3,
    b: 3
};

Using . notation

test1.test;       // -> returns 3

Using [] notation

var propertyName = 'test'
test1[propertyName];       // -> returns 3
jasonscript
  • 6,039
  • 3
  • 28
  • 43