4

Hello i am trying to add an array and a variable and a "." in between them. data is the object i get from json. And valuePickup is a variable.

I am using this

self.GetIndex = function (valuePickup) {
    $http.get("someURL").success(function (data, status, headers, config) {
        console.log(data + "." + valuePickup); //It is not resulting the object
        console.log(data.categories); // this is how i want the above line looks like.
    });
}

It looks something like this. and what i get in return in [object Object].categories

Is there any way to join an array object and a variable.

1 Answer 1

4

Use bracket notation to access property by variable key:

console.log(data[valuePickup]);
Sign up to request clarification or add additional context in comments.

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.