Ahmet
Ahmet

Reputation: 43

Typescript / angular2 Push data to start array[0]

I would like to add data to array. But I want to push start always messages[0] , and shouldnt lost messages datas

this.messages.push(data[0]);

Upvotes: 0

Views: 1019

Answers (1)

LLai
LLai

Reputation: 13416

you want unshift(). push() adds to the end of an array while unshift adds to the beginning (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)

this.messages.unshift(data);

Upvotes: 1

Related Questions