-1

I´ve got a function which should add an element at the start of an array. But I always get an undefined element at the end of my array. I hope someone can help me :)

function putToFirst(e){
   var array = [];
   array.push(e);
   this.arrayList = array.concat(this.arrayList);
}

EDIT:

class List {

  constructor () {
    super()
    this.arrayList = [];
  }

  putToFirst(e) {
      this.ArrayList.unshift(e);
 }
}

thats the class. I create a new object from the class list and call the function putToFirst on this object. But I always get an Array with 'undefinded' in the end

Alex9677
  • 49
  • 1
  • 5

1 Answers1

-4
this.arraylist is wrong this represent a current object you are not currently using any class in above code you just need to change 

  function putToFirst(e){
   var array = [];
   var arrayList=[];
   array.push(e);
  arrayList = array.concat(arrayList);
  console.log(arrayList);
}