I'm seeing a weird issue where splice appears to remove an element at the index + 1 instead of the correct index. For instance, if selectedCourseMediaIndex = 0, then the element at index 1 in the array is removed. Is there any particular reason why this is happening?
courseMedia: [
{
name: 'testing_startup_ideas.mp3',
url:
'https://s3.eu-west-2.amazonaws.com/media.test.co.uk/default/testing_startup_ideas.mp3',
type: CourseContentMediaType.AUDIO,
},
{
name: 'biggest_mistake_founders_make.mp3',
url:
'https://s3.eu-west-2.amazonaws.com/media.test.co.uk/default/biggest_mistake_founders_make.mp3',
type: CourseContentMediaType.AUDIO,
},
],
onEditAudioItemDeleteButtonClick() {
let courseMedia = JSON.parse(JSON.stringify(this.courseMedia));
courseMedia = CourseContentService.deleteCourseMediaByIndex(
courseMedia,
this.selectedCourseMediaIndex
);
}
static deleteCourseMediaByIndex(
courseMedia: ICourseMedia[],
selectedCourseMediaIndex: number
): ICourseMedia[] {
return courseMedia.splice(selectedCourseMediaIndex, 1);
}
question from:
https://stackoverflow.com/questions/65859153/javascript-splice-removes-array-element-at-index-1-instead-of-index 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…