admin管理员组文章数量:1318984
json= new Gson().toJson(name);
where name is of type string.
I am getting error saying "TypeError: invalid 'in' operand obj "
error is in the given part of java script
return type === "array" || type !== "function" &&
( length === 0 ||
typeof length === "number" && length > 0 && ( length - 1 ) in obj );
I have also tried
response=JSON.parse(response);
which is not working.
json= new Gson().toJson(name);
where name is of type string.
I am getting error saying "TypeError: invalid 'in' operand obj "
error is in the given part of java script
return type === "array" || type !== "function" &&
( length === 0 ||
typeof length === "number" && length > 0 && ( length - 1 ) in obj );
I have also tried
response=JSON.parse(response);
which is not working.
Share Improve this question edited Jun 3, 2015 at 15:07 IARI 1,3771 gold badge19 silver badges39 bronze badges asked Nov 26, 2013 at 7:03 user2814799user2814799 5592 gold badges7 silver badges17 bronze badges 4-
what is
responseJson
– Arun P Johny Commented Nov 26, 2013 at 7:04 - response object which i am getting from servlet – user2814799 Commented Nov 26, 2013 at 7:07
- element of type object – user2814799 Commented Nov 26, 2013 at 7:09
-
As the error suggests,
obj
doesn't seem to be a valid operand forin
. – Felix Kling Commented Nov 26, 2013 at 7:18
4 Answers
Reset to default 2by link In operator you can see that
The in operator returns true if the specified property is in the specified object.
in your code ( length - 1 ) in obj
you try checking that property (length - 1)
that numeric in your obj
I think obj
is a string
, so it has the length
property, but does not have numeric properties, so you must catch this case
I closed the code "( length - 1 ) in obj" between parentheses.
return type === "array" || type !== "function" &&
( length === 0 ||
typeof length === "number" && length > 0 && (( length - 1 ) in obj) );
That's working fine for me.
In my case the object was not empty but I needed to add double quotes on the object's key , example :
obj = {params : "paramsInputPreData"}
The Above will produce an error but the one below was okay :
obj = {"params" : "paramsInputPreData"}
so for me the key needed to be quoted as "params"
Hope it helps someone
When you have this error, you need to check the type of your variables, etc., you can always do something like this:
if (typeof x == 'string' || typeof x == 'number') { ... }
本文标签: javascriptTypeError invalid 39in39 operand objStack Overflow
版权声明:本文标题:javascript - TypeError: invalid 'in' operand obj - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742055765a2418284.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论