title: how to set checkbox checked based on value in one array and add value to another array if checked otherwise remove using angular js?
body: <p><a href="https://i.stack.imgur.com/8NrSP.png" rel="nofollow noreferrer">enter image description here</a>Following is just the overview of the code,as given in <strong>html code</strong> i just want to show the <strong>options from options array from set object</strong> and <strong>have to set checkbox checked</strong> to option which is <strong>an answer from answer array</strong> and have <strong>to add new answer</strong> to answer if i check more options with checkbox clicked, and have to <strong>remove answer if checkbox is unchecked</strong>.  </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;script&gt;
  
  var adminApp = angular.module('app',[]);
  
  adminApp.controller('EditController', function ($scope) {
  
     
       $scope.viewQuestions=function(){
  
     set={};  //object in which answer array and option array is present //assume;
  
    var answer= ["answer1", "answer2"]; //answer array assume
   
    var options=["option1,option2,option3,option4"]; //option array assume
    
    var answerType="Multiple";
      }
  
    $scope.updateAnswer =function(isSet,index,answer,set)
      {
          
          for(var i=0;i&lt;set.answer.length;i++)
          {
                if(isSet===set.answer[i])
                {
                    set.answer[index]=isSet;
                }
                else
                {
                 
                  set.answer.splice(index, 1);
               
                }
        }
        
     }
     }
  
  &lt;/script&gt;</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.js"&gt;&lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body ng-app="app" ng-controller="EditController" ng-init="viewQuestions()"&gt;
  &lt;table&gt;
  &lt;tr&gt;
                                        
   &lt;td ng-show="s.answerType === 'Multiple'"&gt;
  &lt;p ng-repeat="o in s.options"&gt;{{$index + 1}}.  &lt;input type="checkbox" 
  name="answer-{{index}}"  
  ng-model="isSet"  value="{{o}}"
  ng-change="updateAnswer(isSet,$index,answer,s)"&gt;{{o}}&lt;/p&gt;
  &lt;/td&gt;
  
  &lt;/tr&gt;
  
  &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>