title: How to push a JSON object to an array in AngularJS
body: <p>I need to push a JSON object to AngularJS and need to check before if the value for one of the objects exist. I need to overwrite the data.</p>
  <pre><code>$scope.setData = function(survey, choice) {
  
    keepAllData.push({
      'surveyId': survey.id,
      'choiceId': choice.id
    });
    console.log(keepAllData);
    toArray(keepAllData);
    alert(JSON.stringify(toArray(keepAllData)));
  
    $scope.keepAllDatas.push({
      'surveyId': survey.id,
      'choiceId': choice.id
    });
    var items = ($filter('filter')(keepAllDatas, {
      surveyId: survey.id
    }));
  
  }
  
  function toArray(obj) {
    var result = [];
    for (var prop in obj) {
      var value = obj[prop];
      console.log(prop);
      if (typeof value === 'object') {
        result.push(toArray(value));
  
        console.log(result);
      } else {
        result.push(value);
        console.log(result);
      }
    }
    return result;
  }
  </code></pre>
  <p>If the survey id exists in keepalldata, I need to change the recent value with choiceid. Is it possible to do with AngularJS?</p>