creating own javascript join and push methods I'm a newbie trying to write my own push() and join(). This isn't very serious, just an exercise.
This is what I got so far


function Errey(...values){
    this.name=values
    }
Errey.prototype={
  constructor:Errey,
    //join method
  myJoin(union = ' '){
  let result=""
  const length = this.name.length
  for(let i=0; i&lt;length; i++)
  { 
   i&lt;length-1 ? result += this.name[i] + union: result+=this.name[i]
  }
  return result
  },
    //push method
    myPush(value){
    this.name = [...this.name, value]
    return this.name.length
    }
  }

//run a few examples
const myArray = new Errey("3","blue","1","brown")
//we'll mutate myArray anyways using const or let
let joined  = myArray.myJoin()
let a = myArray.myPush("hey")
console.log("joined new array: ",joined, "\n\npush-mutated array: ", myArray.name, "\n\npush return value: ", a)



I'm aware an object is returned instead of an array. I guess you might help me out there. Should I use factory functions here? I don't know how would I create a prototype for such a thing...
Any improvements on the main code you'd suggest?
first of all you can use the &quot;new&quot; class syntax instead of changing the prototype directly.
This is how I would do it:
class Errey {
    #currentArray;

    constructor(...elements) {
        this.#currentArray = elements;
    }

    get errey() {
        return this.#currentArray;
    }

    push(...elements) {
        const startLength = this.#currentArray.length;
        elements.forEach((curEl, index) =&gt; this.#currentArray[index + startLength] = curEl);
        return this.#currentArray.length;
    }

    join(union = &quot; &quot;) {
        return this.#currentArray.reduce((prev, cur) =&gt; prev + union + cur);
    }
}

//run a few examples
const myArray = new Errey(&quot;3&quot;,&quot;blue&quot;,&quot;1&quot;,&quot;brown&quot;)

console.log(myArray.join(&quot;, &quot;));
console.log(myArray.push(&quot;Subscribe&quot;, &quot;To&quot;, &quot;Him&quot;));
console.log(myArray.errey);

push:
the standard array.prototype.push allows for multiple elements to be added at once, so I allow multiple elements and loop over them using forEach, you could also do [...this.#currentArray, ...elements] (or use Array.prototype.concat()).
join:
here I use reduce to create a join operation. Reduce takes the first 2 elements and applies a function on them (in this case a + union + b), makes them the new first element and repeats that until there is only one element left, our joined erray.
I also made the internal Array private using the prefixed # and created a getter (get errey()) instead, this way the internal array can only be changed using the push method.
Using the factory pattern (which I personally prefer):
const Errey = (...elements) =&gt; {
    
    const push = (...newElements) =&gt; {
        const startLength = elements.length;
        newElements.forEach((curEl, index) =&gt; elements[index + startLength] = curEl);
        return elements.length;
    };

    const join = (union = &quot; &quot;) =&gt; elements.reduce((prev, cur) =&gt; prev + union + cur);

    const get = () =&gt; elements;

    return {
        push,
        join, 
        get,
    };
};

const myArray = Errey(&quot;3&quot;,&quot;blue&quot;,&quot;1&quot;,&quot;brown&quot;)

console.log(myArray.join(&quot;, &quot;));
console.log(myArray.push(&quot;Subscribe&quot;, &quot;To&quot;, &quot;Him&quot;));
console.log(myArray.get());