[英]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 我有一个包含一些元素的Java脚本数组,现在我想按值从数组中删除元素,我正在发布代码
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. 使用splice()
函数。 So if you want to remove the item at index 5, you would type strDate.splice(5,1);
因此,如果要删除索引5处的项目,请键入strDate.splice(5,1);
The 1
being how many items to remove starting at that index. 1
是从该索引开始要删除的项目数。
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 IE:年-月-日期
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.