Reputation: 1571
I have upgraded to jQuery 1.10.2 in my application, and I am getting an error in my code (in $.each
).
'invalid 'in' operand e' .
This error occured after upgrading jQuery. In 'this._currentFilterbarValue
', there is a string value which I need to check against some condition.
_CheckForSkipInput: function () {
var IsSkip = false;
if (this._currentFilterColumn.type == "String") {
var stringSkipInput = new Array(">", "<", "=", "!");
$.each(this._currentFilterbarValue, function (index, value) {
if (jQuery.inArray(value, stringSkipInput) != -1)
IsSkip = true;
});
}
return IsSkip;
},
Upvotes: 3
Views: 9014
Reputation: 56509
What you are trying is to iterate through the characters in this._currentFilterbarValue
(which is a string) and therefore jQuery.each()
is failing
The
$.each()
function can be used to iterate over any collection, whether it is an object or an array.
So try like
var IsSkip = false;
if (this._currentFilterColumn.type == "String") {
var stringSkipInput = new Array(">", "<", "=", "!");
for (var i = 0; i < s.length; i++) {
if (jQuery.inArray(s[i], stringSkipInput) != -1) IsSkip = true;
}
}
return IsSkip;
},
Another approach,
Converting your string this._currentFilterColumn
to character array
and then iterating using $.each()
var arr = this._currentFilterColumn.split(""); //Converting a string to char array
$.each(arr, function (index, value) { //Now iterate the character array
if (jQuery.inArray(value, stringSkipInput) != -1) IsSkip = true;
});
Upvotes: 4