0

This might be a dumb question, but I can't figure this out. I have an array of objects with string values:

$scope.groups = [{name: "first"}, {name: "second"}];

And I have a bunch of items like this:

$scope.items = {first: [/*stuff*/], second: [/*stuff*/};

"first" and "second" are not explicitly defined, they are retrieved from server. Is there any way to use $scope.groups[0].name as a part of $scope.items.<here>? Or perhaps there's a better solution?

2 Answers 2

2

You can use JavaScript associative array syntax:

$scope.items[$scope.groups[0].name]

You can utilize this format to both get and set the value in $scope.items. You will, of course, need to at least initialize via $scope.items = {}; before attempting this.

Sign up to request clarification or add additional context in comments.

Comments

0

Yes, you can define it as follows:

$scope.items[$scope.groups[0].name] = [/*stuff*/];

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.