0

I have this array

var user = {
    "tester": {
        id: "1",
        name: "tester"
    }
};

and this function

function get(a, b) {
return user[a].b
}
get('tester', 'id')

How should I fix it so that the result can be 1? Thank for your helps

3
  • 3
    FYI: 'user' is not an array, it's an object. Arrays use square brackets and numeric keys. Commented Mar 5, 2013 at 2:43
  • 1
    var testerId = user.tester.id Commented Mar 5, 2013 at 2:57
  • Thank you Zach for pointing that out. As you can see, I'm not a pro. Commented Mar 5, 2013 at 3:04

2 Answers 2

3
function get(a, b) {
    return user[a][b];
}
Sign up to request clarification or add additional context in comments.

Comments

1

Try this:

function get(a, b) {
    return user[a][b];
}
get('tester', 'id');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.