invert push order

1

I'm using push in a request to put new element in a list, but I noticed that push puts the last result down. I want to reverse this.

I'm using v-for to list, but I believe the "fix" will be in the same push ... follow the code:

   dados.retornodosite.push(response.data);

How to invert the array?

    
asked by anonymous 12.09.2018 / 22:52

2 answers

8

UNSHIFT

If you want you can use the unshift method. If you'd like to learn more read here .

var nomes = ["João", "Maria", "André", "Marcia"];
nomes.unshift("Luís","Adriano");

console.log(nomes);
    
12.09.2018 / 23:03
1

Splice

If the object is an array, the push will insert at the end. To enter at the beginning you can use splice

Example:

var final = 4;
var comeco = 1;

var arr = [2, 3];

arr.splice(0, 0, comeco);

console.log(arr);

arr.push(final);

console.log(arr);

Result:

// inicial
[2, 3] 

// depois do splice
[1, 2, 3]

// depois do push
[1, 2, 3, 4]
    
12.09.2018 / 23:02