Sedbol
@Sedbol

Как удалить массив в массиве?

Как удалить массив в массиве? Что бы он был не Nan а просто что бы его вообще не было?
let timerTab =[];
    timerTab.push([10,new Date().getTime()+6000]);
    timerTab.push([11,new Date().getTime()+9000]);


   setInterval(function () {
        timerTab.forEach(function (timer) {
            if(timer[1]===new Date().getTime() || timer[1]<new Date().getTime()){
                console.info("Таймер истек",timer[0])
                timer.splice(timer)
            }else{
                console.info(timer[1]-new Date().getTime())
            }

        } )
    },1000)
  • Вопрос задан
  • 129 просмотров
Решения вопроса 2
sergiks
@sergiks Куратор тега JavaScript
♬♬
В этой задаче можно использовать Array.filter()
let timerTab =[];
timerTab.push([10,new Date().getTime()+6000]);
timerTab.push([11,new Date().getTime()+9000]);

setInterval(function () {
    const now = Date.now();
    timerTab = timerTab.filter(function (timer) {
        if (timer[1] <= now) {
            console.info("Таймер истек", timer[0]);
            return false; // не войдет в выбранные
        } else {
            console.info(`${timer[0]}: ${timer[1] - now}`);
            return true; // войдет в выбранные
        }
    })
}, 1000)
Ответ написан
Комментировать
john36allTa
@john36allTa
alien glow of a dirty mind
let timerTab =[];
    timerTab.push([10,new Date().getTime()+6000]);
    timerTab.push([11,new Date().getTime()+9000]);


   setInterval(function () {
        timerTab = timerTab.filter(function (timer) {
            if(timer[1]===new Date().getTime() || timer[1]<new Date().getTime()){
                console.info("Таймер истек",timer[0])
                return false
            }else{
                console.info(timer[1]-new Date().getTime())
								return true
            }

        } )
    },1000)
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы