标签云

微信群

扫码加入我们

WeChat QR Code

How do I remove one item based on both the courseID and endDate from the following javascript object?

    window.MyCheckedCourses = [
        { courseID: '123', endDate: '6/7/2010' },
        { courseID: '123', endDate: '3/9/2003' },
        { courseID: '456', endDate: '3/9/2003' }  
    ]; 


that's not an object, it's an "array" of objects.

2018年08月16日25分32秒

window.MyCheckedCourses is an array, not a jQuery object.

2018年08月16日25分32秒

Where is the jQuery?

2018年08月16日25分32秒

As everyone else has said, that's an array of objects, and has nothing to do with jQuery. You case just use MyCheckedCourses.splice(startIndex, count); to remove whichever elements you want from the array.

2018年08月16日25分32秒

Thanks so much for everyone's help. How would I remove a single object from the JavaScript array of objects based on both the courseID and endDate values of the object I want removed?

2018年08月16日25分32秒

Although id makes me think of "unique" (and I know the title says "single object", but that could mean a "single object" in several places), if there are possible multiple matches, you'll have to (remove the break; and) loop backwards

2018年08月15日25分32秒

You're right Ian, I'm going to update my answer.

2018年08月15日25分32秒