我目前已經獲得了一組用於設置時間間隔並清除它們的JavaScript函數。 問題是;間隔被存儲在一個陣列(intervals[]
)刪除JS數組元素
config: {
settings: {
timezone: 'Australia/Perth,',
base_url: location.protocol + '//' + location.hostname + '' + ((location.pathname) ? location.pathname : ''),
api_url: '/api/'
},
intervals: []
}
有與該陣列工作兩個功能: 第一個是間隔設定器:
interval_set: function(time, name, callback) {
this.config.intervals[name] = setInterval(callback, time);
}
和第二個是間隔更清晰
interval_clear: function(name) {
if (this.config.intervals[name]) {
clearInterval(this.config.intervals[name]);
this.debug('Interval: "' + name + '" cleared.', 1);
} else {
this.debug('No interval: "' + name + '" found.', 1);
}
}
現在的問題是我需要從中刪除所述區間tervals數組,雖然你可以看到 - 它沒有設置一個特定的鍵。
的間隔排列如下:
Array[0]
derp: 1
我一直在使用splice()
嘗試,但似乎並沒有工作。你會建議我做什麼?我應該將它與索引存儲在數組中嗎?
謝謝:)
數組:數字索引;對象:字符串鍵。看起來你把他們混在一起。 – Bergi
@Bergi感謝您指出,現在將解決我的愚蠢:) – Darren