admin管理员组文章数量:1323734
I am attempting to convert a javascript mixed case Array to lowercase. I've been searching for solutions, but the answers I am finding are for C#, C, or Java. Can anyone give me suggestions on how to proceed?
Here's the relevant JS code I'm working with:
var newArray = oldArray.map(oldArray.toLowerCase);
I am attempting to convert a javascript mixed case Array to lowercase. I've been searching for solutions, but the answers I am finding are for C#, C, or Java. Can anyone give me suggestions on how to proceed?
Here's the relevant JS code I'm working with:
var newArray = oldArray.map(oldArray.toLowerCase);
Share
Improve this question
edited Oct 12, 2016 at 2:45
Jeff Swearingen
asked Oct 11, 2016 at 19:57
Jeff SwearingenJeff Swearingen
661 silver badge9 bronze badges
1
- 2 var newArray = oldArray.map(function (e) { return e.toLowerCase()) or in ES2015 .map(e => e.toLowerCase()) – Pete TNT Commented Oct 11, 2016 at 19:59
4 Answers
Reset to default 3Try:
let array = ["abC", "aDB", "bdD"];
let newArray = array.map((item) => {
return item.toLowerCase();
});
console.log(newArray);
Remember: the map method takes a callback with three arguments, with the first being the current value being processed in the array. Think of it as an iterative function, iterating on each item in the array. The map method must also return a value for each iteration, otherwise it will return undefined for that specific value in the process/iteration.
["ABC", "dEf"].map(function(item) { return item.toLowerCase(); });
oldArray.map(function(item) { return item.toLowerCase(); });
Depending on the language, you may prefer using toLocaleLowerCase (Turkish example).
Try
var newArray = oldArray.map(function (val) { return val.toLowerCase(); });
Here is some documentation on the map function.
var newArray = oldArray.map(function(x){ return x.toLowerCase() })
本文标签: How do I convert a mixed case array to lowercase using the map function in JavascriptStack Overflow
版权声明:本文标题:How do I convert a mixed case array to lowercase using the map function in Javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742119001a2421605.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论