Attach array object and string variable in javascript or angularjs

Hi, I am trying to add an array and a variable and "." between them. datais the object i get from json. A valuePickupis a variable.

I use 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 for[object Object].categories

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

+4
source share
1 answer

Use the legend to access the property using the variable key:

console.log(data[valuePickup]);
+4
source

Source: https://habr.com/ru/post/1584790/


All Articles