title: Redux reducer, check if value exists in state array and update state
body: <p>So I've got an array <code>chosenIds[]</code> which will essentially hold a list of <code>ids (numbers)</code>. But I'm having trouble accessing the state in my reducer to check whether the <code>ID I parsed to my action</code> is in the array.</p>
  
  <pre><code>  const initialState = {
    'shouldReload': false,
    'chosenIds': [],
  };
  
  export default function filter(state = initialState, action) {
    switch (action.type) {
  
  
   case ADD_TYPE:
        console.log(state.chosenIds, "Returns undefined???!!!");
  
        // Check if NUMBER parsed is in state
        let i = state.chosenIds.indexOf(action.chosenId);
  
        //If in state then remove it
        if(i) {
          state.chosenIds.splice(i, 1);
          return {
            ...state.chosenIds,
            ...state.chosenIds
          }
        }
        // If number not in state then add it 
        else {
          state.chosenIds.push(action.chosenId)
          return { ...state.chosenIds, ...state.chosenIds }
        }
  </code></pre>
  
  <p>I'm not to sure what's going on...But when I log <code>state.chosenIds</code>, it returns undefined? It doesn't even return the initial empty array <code>[]</code> .</p>
  
  <p>Basically what this function is suppose to do is check to see if the <code>action.chosenId</code> is in the <code>state.chosenIds</code>, If it is, then remove the <code>action.chosenId</code> value, if it's not, then add the <code>action.chosenId</code> to the state.</p>