title: Javascript : typeerror not a function
body: <p>I have a snippet of code that updates records in a json object representing a musical album collection. The function written here updates the records given an album ID, a property ("tracks"), and a value ("albumName")</p>
  
  <p>The error I get below is:</p>
  
  <blockquote>
    <p>"message": "Uncaught TypeError: collection[id][prop].push is not a function",</p>
  </blockquote>
  
  <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>    var collection = {
          "2548": {
            "album": "Slippery When Wet",
            "artist": "Bon Jovi",
            "tracks": [ 
              "Let It Rock", 
              "You Give Love a Bad Name" 
            ]
          },
          "2468": {
            "album": "1999",
            "artist": "Prince",
            "tracks": [ 
              "1999", 
              "Little Red Corvette" 
            ]
          },
          "1245": {
            "artist": "Robert Palmer",
            "tracks": [ ]
          },
          "5439": {
            "album": "ABBA Gold"
          }
      };
      
      // Only change code below this line
      function updateRecords(id, prop, value) {
        if(!value){
          delete collection[id][prop];
          return collection;
        }
        if(prop === "tracks"){
          if(!collection[id].hasOwnProperty('tracks')){
            collection[id].tracks="";
          }
          if(value){
            collection[id][prop].push(value);
          }
        } else {
          collection[id][prop] = value;
        }
      
        return collection;
      }
      
      updateRecords(5439, "tracks", "Take a Chance on Me");</code></pre>
  </div>
  </div>
  </p>
  
  <p>Some other test case scenarios</p>
  
  <p><a href="https://i.stack.imgur.com/hnDXa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hnDXa.png" alt="enter image description here"></a></p>