0

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. I have tried this same method for other array but it is working,but it is not working for this array.

2 Answers 2

1

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 !=.

Sign up to request clarification or add additional context in comments.

Comments

0
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!!!!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.