简体   繁体   中英

How to remove elements from javascript array by value

i have a java script array which consist of some elements ,now i want to remove element by value from my array ,I am posting my code

 var strDate = [2015-10-26,2015-10-27,2015-10-28,2015-10-29,2015-10-30,2015-10-31,2015-11-01];

 var index = strDate.indexOf(new Date(calEvent.start).toISOString().slice(0, 10));
                //strDate.splice(new Date(calEvent.start).toISOString().slice(0, 10));
delete strDate[index];

how to delete elements in an arry

Use the splice() function. So if you want to remove the item at index 5, you would type strDate.splice(5,1); The 1 being how many items to remove starting at that index.

You may want to put your items in the array in quotation marks as they are being evaluated as integers and being subtracted from each other. IE: Year - Month - Date

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM