-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
  • 1
    Square bracket notation is your answer: console.log(test1[i]). Commented Jul 23, 2014 at 2:32
  • I don't understand what you're asking Commented Jul 23, 2014 at 2:33

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

Comments

1

Do it this way:

var test1 = {
    test : 3
};
console.log(test1[i])

1 Comment

Code only answers are not liked, you should add an explanation.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.