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
Add a ment  | 

4 Answers 4

Reset to default 3

Try:

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