A
A
alaskafx2021-09-03 21:19:37
Vue.js
alaskafx, 2021-09-03 21:19:37

How to shift an array by removing the first element?

I want to make some "shift" of the array so that it works like this:

there is an array:

[
  {
   id: 1
   },
   {
    id: 2
    }
]


after that another object should be added, but the very first object (where id: 1) should be removed, creating a "shift" .

I wrote this code:

setInterval(() => {
          step++;
          // let rand = this.cases[getRandomInt(3)]
          carousel.style.right = step * 2 + "px";
          // carousel.appendChild(rand);
        }, time);
        setInterval(() => {
           this.cases.push(this.cases[getRandomInt(8)])
            this.cases.shift()
        }, 1000);


well, and an array:
uDAh40w.png

But my code does not work the way I described it above.
How to do the same?


after that another object should be added, but the very first object (where id: 1) should be removed, creating a "shift" .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shmatuan, 2021-09-03
@shmatuan

https://ru.vuejs.org/v2/guide/transitions.html#Ani...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question