Reputation: 33
Why am I getting this error? Error from the chrome's console...
Uncaught TypeError: Array.prototype.indexOf called on null or undefined
at indexOf (<anonymous>)
at Function.c.inArray (zepto.js:2)
at HTMLDivElement.<anonymous> (index.html:97)
at HTMLDivElement.j (zepto.js:2)
c.inArray @ zepto.js:2
(anonymous) @ index.html:97
j @ zepto.js:2
And this is the code on and after the 97th line.
if ($.inArray($("#recipient-email").val(), recipientList) == -1) {
recipientList.push($("#recipient-email").val());
localStorage.setItem(
"recipient-list",
JSON.stringify(recipientList)
);
Upvotes: 3
Views: 1241
Reputation: 4352
It seems that your code is fine, but the problem is at another point. As I see, you are using jQuery
and sometimes it doesn't parse / grab results from "#recipient-email"
div or so.
But it also doesn't return an empty array of Array.prototype
itself and as a result, any Array.prototype
method will return you the following error.
You should add some code for handling such scenario, like:
I don't know in which variable your array is stored, but I guess you would understand my logic.
if ($.inArray($("#recipient-email").val(), recipientList) === null) {
$.inArray($("#recipient-email").val(), recipientList) === []
}
Upvotes: 2