Javascript - Making Array Index toLowerCase() not working

耗尽温柔 提交于 2019-12-02 05:56:45

i updated your fiddle

https://jsfiddle.net/af91r2cq/6/

colorArr[i] = colorArr[i].toString().toLowerCase().trim(); // FIX HERE

your way was really close ;)

You need to set the value back

It should be

colorArr[i] = colorArr[i].toString().toLowerCase().trim(); // FIX HERE

Or simply

colorArr = colorArr.map(function(value){ return value ? value.toLowerCase().trim() : ""; });

Another way change all defined values in the array to lowercase is to use the jQuery.map function like so:

colorArr = $.map(colorArr, function(item, i) {
  if(item !== undefined) {
    return item.toString().toLowerCase().trim();
  }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!