Join the Stack Overflow Community
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I have an array with two keys like id and selected values its like below

$scope.overview =[{'id':1,'selectedvalues':[a,e,o]},{'id':2,'selectedvalues':[aa,ee,oo]},{'id':3,'selectedvalues':[aaa,eee,ooo]}];

I need to update after i am adding values 'h' for id =1 i need to update my array like

$scope.overview =[{'id':1,'selectedvalues':[a,e,o,h]},{'id':2,'selectedvalues':[aa,ee,oo]},{'id':3,'selectedvalues':[aaa,eee,ooo]}];

there is any other way in anuglar js currently i am handling in javascript like

if (this.selectedCategoryOverview.length > 0) {

    for (var i in updateDropown) {

       if (catid == updateDropown[i].id){
        overviewUpdate = false;

          updateDropown[i].selectedValues = tempSelectValuesArray;
       }

    }

    }
    if(overviewUpdate){
        this.selectedCategoryOverview.push({
        'id': catid,
        'selectedValues': tempSelectValuesArray
    });
    }
share|improve this question

Try using filter,

$filter('filter')($scope.overview, { id: catid })[0].selectedvalues = tempSelectValuesArray;
share

Try to use array.find to find existing overview by id. If find method returns a value - just update the value, and add the value otherwise.

In pseudocode:

foundObject = array.find()
if(foundObject)
  update()
else
  pushNew()
share

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.