Monday, 5 August 2019

JavaScript Array undefined element

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

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...