Javascript-使toLowerCase()的数组索引不起作用 [英] Javascript - Making Array Index toLowerCase() not working
本文介绍了Javascript-使toLowerCase()的数组索引不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使所有数组索引都小写字符串,但是它不起作用.我在这里查看了其他答案,并尝试了他们的解决方案,例如在添加toLowerCase
之前使用toString()
,但是它不起作用,这很奇怪.
I'm trying to make all array indexes lowercase strings, but it's not working. I looked at other answers on here and tried their solutions like using toString()
before adding toLowerCase
but it doesn't work, which is weird.
我在此处创建了问题的jsfiddle.
I created a jsfiddle of the problem here.
JS:
$(colorArr).each(function(i, item) // loop thru each of elements in colorArr and make lowercase + trim
{
if(colorArr[i] !== undefined) // check if colorArr index undefined
{
colorArr[i].toString().toLowerCase().trim(); // FIX HERE
/* TRIED - DIDN'T WORK!
colorArr[i].toLowerCase().trim();
*/
}
});
推荐答案
我更新了您的小提琴
https://jsfiddle.net/af91r2cq/6/
colorArr[i] = colorArr[i].toString().toLowerCase().trim(); // FIX HERE
你的路真的很近;)
这篇关于Javascript-使toLowerCase()的数组索引不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文