title: Removing element from multidimensional array or object in javascript
body: <p>I have a rooms object, inside that object has many rooms array, and in each room there are users element.</p>
  
  <pre><code>var rooms = {"room1":["user1","user2"],"room2":["user1","user2","user3"]};
  </code></pre>
  
  <p>How do I write a function that remove a specific user from the rooms array when called?</p>
  
  <pre><code>function leaveRoom(user,room){
    if(typeof room != "undefined"){
  //remove user from the specific room ONLY if room argument is passed
    } else {
  //remove user from all rooms    
    }
  }
  </code></pre>
  
  <p>I have tried to use splice with the index of the element but it doesn't work.</p>
  
  <pre><code>Array.prototype.remove = function(value) {
      if (this.indexOf(value)!==-1) {
         this.splice(this.indexOf(value), 1);
         return true;
     } else {
        return false;
     };
  } 
  var roomName="room1",
      userName="user1";
  rooms[roomName].remove(userName);
  </code></pre>
  
  <p>actually I'm not even sure if it is an object or array anymore. Please help thanks</p>