EDIT
The following question How do I empty an array in JavaScript? does not answer the question i.e. I get how to set / reset an array but that was not my question. I want to to do is:
- set the key with a dynamic value e.g. UUID and,
- then set element[0] (the above) to true in one line of code.
QUESTION
Code base: Angular 1.5x, lodash 4.x
Seems like a basic question but cannot find an answer. Is it possible using JS, Angular or lodash to reset an array and set it at the same time per the example below. As per the example below the array will keep pushing unless I set reset it. Why you ask, example if I'm using a UUID as key in the HTML e.g.
HTML
<li id="{[{contactus.app_id}]}"
ng-show="view.state[item.uuid]"
ng-repeat="item in collection.items track by item.uuid">
</li>
JS (Angular)
NOTE: this code works and I could also use replace $scope.view.state.length = 0;
with $scope.view.state = [];
but my question is more along the lines of reseting an array, adding a dynamic key and setting it to true all in one line of code. The complexity is in the dynamic key.
$scope.view = {state:[]};
$scope.setViewState = function (id) {
// how can I collapse the following 2 lines of code into one
$scope.view.state = [];
$scope.view.state[id] = true;
};