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
[].unshift()
broken in your browser?! – lonesomeday Dec 9 '16 at 15:21e
? What'sthis
? Try providing a minimal reproducible example. – Quentin Dec 9 '16 at 15:21unshift
onthis.arrayList
, you'll mutate the array instead of replacing it with a new one. – user3297291 Dec 9 '16 at 15:25