title: Reverse engineer an array object
body: <p>I know that an array is essentially an object with the indexes as the keys, and the elements as the values, so I'm trying to reverse engineer an array with some methods as practice and learn since I'm new to JS and coding in general. I was able to recreate the following methods: push, pop, unshift, shift. Now my question is, is it possible to make it so that when I console log the object, it looks like an array rather than an object? I can't seem to figure it out without using an actual array and the push method. I would appreciate it if I could be led in the direction of the answer or given hints/things to look up and learn rather than a code answer. Also, any suggestion to improve the code I already written would be much appreciated. Thank you in advance!</p>
  <p>Here's the object I created:</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>function createArray() {
      let index = -1;
      const obj = {
          push: (...element) =&gt; {
              for (let i = 0; i &lt; element.length; i++) {
                  index++;
                  obj[index] = element[i];
              }
          },
          pop: () =&gt; {
              let current = obj[index];
              delete obj[index];
              index--;
              return current;
          },
          shift: () =&gt; {
              let current = obj[0];
              for (let i = 0; i &lt; index; i++) {
                  obj[i] = obj[i + 1];
              }
              delete obj[index];
              index--;
              return current;
          },
          unshift: (...element) =&gt; {
              index += element.length;
              for (let i = index; i &gt;= 0; i--) {
                  if (i &gt;= element.length) obj[i] = obj[i - element.length];
                  else obj[i] = element[i];
              }
              return index;
          }
      }
      return obj;
  };
  
  //test:
  const array = createArray();
  array.push(4, 5, 6, 7);
  array.unshift(0, 1, 2, 3);
  array.shift();
  array.pop();
  
  console.log(array);</code></pre>
  </div>
  </div>
  </p>