-1

I have an array of objects that I want to convert everything inside in this array to be lowercase. Can someone help with this:

Original:

const array_pairs = [
{
    "name": "Master",
    "contract": "asxcxcx",
    "deployer": "BCCCCCC"
},
{
    "name": "Master2",
    "contract": "bcxcssDA",
    "deployer": "ttttttttTTtttttt"
}]

Desired Format:

const array_pairs = [
{
    "name": "master",
    "contract": "asxcxcx",
    "deployer": "bcccccc"
},
{
    "name": "master2",
    "contract": "bcxcssda",
    "deployer": "tttttttttttttttt"
}]
4
  • 4
    Please review How do I ask a good question? Your best bet here is to do your research, search for related topics on SO and elsewhere, and give it a go. If you get stuck and can't get unstuck after doing more research and searching, post a minimal reproducible example showing your attempt and say specifically where you're stuck. People will be glad to help. Commented Oct 20, 2022 at 11:27
  • 1
    A very simple and slightly unorthodox solution would be to use JSON.parse(JSON.stringify(array_pairs).toLowerCase()). This will work as long as it's fine that your object keys also get lower-cased (in your example there were no upper-case characters in the keys so I guess it's OK). Commented Oct 20, 2022 at 11:48
  • Sorry if i wasn't clear. I went through stack overflow for a similar issue but couldn't find the right solution to my problem and got stuck for quite a while before I decided to post the question here. but this JSON method is perfect. thanks so much! Commented Oct 20, 2022 at 11:59
  • Does this answer your question? Lowercase JavaScript object values Commented Oct 20, 2022 at 12:15

1 Answer 1

0

const array_pairs = [
{
    "name": "Master",
    "contract": "asxcxcx",
    "deployer": "BCCCCCC"
},
{
    "name": "Master2",
    "contract": "bcxcssDA",
    "deployer": "ttttttttTTtttttt"
}];
const tempArray = array_pairs.map((obj)=>{
    const tempObj={}
  for (let key in obj){
    tempObj[key]=obj[key].toLowerCase();
  }
    return tempObj
});
console.log(tempArray)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.