Skip to content
Advertisement

Delete record from an array of objects in javascript

I have an array of objects that I get from an api, I get the data but I want to remove the ones that have a finish status after x time.

First I must show all the records, after a certain time the records with FINISH status must be deleted

I am using vue.

This is the response I get:

JavaScript

This is the method that obtains the information:

I use setTimeout to be able to delete the records with FINISH status after a certain time

JavaScript

I have tried going through the array and making a conditional and it works for me, but when I call the method again I get the records with FINISH status again. I need to call the method every time since the data is updated

JavaScript

maybe I need to order in another way, or that another javascript method I can use

Advertisement

Answer

Code that you need on CodeSandBox. It sure works.

https://codesandbox.io/s/vue-getdata-and-filter-it-after-delay-6yrj16?file=/src/components/HelloWorld.vue

Use filter for your case: turn => turn.status !== 'FINISH'

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement