[英]How to filter single data from array using javascript/jquery?
var auditorListValue = ["", "1", "2", "3", "4"]; var oldAuditGroupId = 3; var auditorListValue = auditorListValue.filter(function (item) { return item !== oldAuditGroupId; }); console.log(auditorListValue);
<!DOCTYPE html> <html> <head> <title></title> </head> <body> </body> </html>
I want to remove this "3" from array and push remaining data into array but it is not working. 我想从数组中删除此“ 3”并将剩余数据推入数组,但是它不起作用。 I have tried this same method for other array but it is working,but it is not working for this array.
我已经为其他数组尝试了相同的方法,但是它正在工作,但是不适用于此数组。
It is because in your original array you have strings and you are comparing strings to a number using !==
. 这是因为在原始数组中有字符串,并且正在使用
!==
将字符串与数字进行比较。 IT will always return false
unless both of the items have the same type or you compare using !=
. 除非两个项目的类型相同或您使用
!=
进行比较,否则IT始终将返回false
。
var auditorListValue = ["", "1", "2", "3", "4"];
var oldAuditGroupId = "3";
var auditorListValue = auditorListValue.filter(function (item) {
return item !== oldAuditGroupId;
});
console.log(auditorListValue);
This will work!!! 这将工作!!! You are filtering integer instead of String.
您正在过滤整数而不是字符串。
I hope you understand!!!! 我希望你明白!!!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.