title: Best way to flatten JS object (keys and values) to a single depth array
body: <p>I have written this small function to get all keys and values of an object and store them into an array. The object might contain arrays as values...</p>
  
  <p><code>Object { 0: [1,2,3,4] }</code> to <code>[0,1,2,3,4]</code> converting all elements to integers</p>
  
  <p>I wonder whether there is a faster/cleaner way to do so:</p>
  
  <pre><code>function flattenObject(obj) {
      // Returns array with all keys and values of an object
      var array = [];
      $.each(obj, function (key, value) {
          array.push(key);
          if ($.isArray(value)) {
              $.each(value, function (index, element) {
                  array.push(element);
              });
          }
          else {
              array.push(value);
          }
      });
  
      return array
  }
  </code></pre>