Delete items from store array issue

I am attempting to remove an array element by one of its objects id properties. this is my method
const removeSound = async (soundId) => {
const audioPlayer = getAudioPlayer(soundId)
const status = getSelectedScene().sounds.find((sound) => sound.id === soundId).status;

// Stop any audio players that are playing for this sound and remove them
if (status == 'playing') {
audioPlayer.stop()
//!= how? delete audioPlayer
}

// Remove the sound from the scene
setSelectedScene('sounds', (sound) => sound.id !== soundId)
}
const removeSound = async (soundId) => {
const audioPlayer = getAudioPlayer(soundId)
const status = getSelectedScene().sounds.find((sound) => sound.id === soundId).status;

// Stop any audio players that are playing for this sound and remove them
if (status == 'playing') {
audioPlayer.stop()
//!= how? delete audioPlayer
}

// Remove the sound from the scene
setSelectedScene('sounds', (sound) => sound.id !== soundId)
}
right now all im getting when running this is:
RangeError: Invalid array length
RangeError: Invalid array length
3 Replies
hcker2000
hcker2000OP2mo ago
I am thinking maybe because im removing the last one?
REEEEE
REEEEE2mo ago
setSelectedScene('sounds', s => s.filter(sound => sound.id !== soundId))
setSelectedScene('sounds', s => s.filter(sound => sound.id !== soundId))
or
setSelectedScene('sounds', sound => sound.id !== soundId, undefined)
setSelectedScene('sounds', sound => sound.id !== soundId, undefined)
not sure about the second one though
hcker2000
hcker2000OP2mo ago
ahh ok so probably better to do the first then
Want results from more Discord servers?
Add your server