简体   繁体   中英

toString() on JS associative array

Is it possible to call '.toString()' on an associative array in Javascript.

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:

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:

Uncaught TypeError: Cannot call method 'toString' of undefined

Try:

JSON.stringify(jsonData['item'])

This will return you a String , so toString() is not needed.

Update : Concatenate the returned value with an empty string literal:

var theString = ("" + jsonData['item']).toLowerCase();
var theString = ("" + jsonData.item   ).toLowerCase();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM