[英]toString() on JS associative array
Is it possible to call '.toString()' on an associative array in Javascript. 是否可以在Javascript中的关联数组上调用'.toString()'。
var theString = jsonData['item'].toLowerCase();
var theString = jsonData.item.toLowerCase();
Neither of these work for me in converting the array item's value to lower case. 在将数组项的值转换为小写时,这些都不适用于我。
In PHP I can do this by: 在PHP中,我可以通过以下方式实现:
strtolower($array['item']);
Thanks in advance :) 提前致谢 :)
EDIT: Here is my exact code: 编辑:这是我的确切代码:
var correctAnswer = jsonData[setname][qname]['answers'][answerval];
if(lockcase == false){
orrectAnswer = correctAnswer.toString().toLowerCase();
}
And here is the message from the Chrome debug menu: 以下是Chrome调试菜单中的消息:
Uncaught TypeError: Cannot call method 'toString' of undefined 未捕获的TypeError:无法调用未定义的方法'toString'
Try: 尝试:
JSON.stringify(jsonData['item'])
This will return you a String
, so toString()
is not needed. 这将返回一个String
,因此toString()
。
Update : Concatenate the returned value with an empty string literal: 更新 :将返回的值与空字符串文字连接:
var theString = ("" + jsonData['item']).toLowerCase();
var theString = ("" + jsonData.item ).toLowerCase();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.