Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

129
Views
creating a function that converts an array to uppercase

so lets say I created an array that is ..

let foods = ['oranges', 'pears', 'peaches]

now I want to create a function that allows me to select any of the elements and convert it to uppercase letters how would I go about doing that?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

In javascript you could do something like:

let foods = ["oranges", "pears", "peaches"];

function uppercase(array, index) {
  for (i = 0; i < array.length; i++) {
    if (i == index) {
      console.log(array[i]);
      result = array[i].toUpperCase();
      return result;
    }
  }
}

result = uppercase(foods, 1);
console.log(result);
about 4 years ago · Juan Pablo Isaza Report

0

I hope this can help you:

example 1: convert to uppercase using index of element

let foods = ['oranges', 'pears', 'peaches']

const convertToUppercase = (index) => {
    return foods[index].toUpperCase()
}

console.log(convertToUppercase(0))

example 2: convert to uppercase by element (text you want to convert)

let foods = ["oranges", "pears", "peaches"];

const convertToUppercase = (element) => {
  return element.toUpperCase();
};

foods.forEach((element) => {
  console.log(convertToUppercase(element));
});

example 3: convert the entire array to uppercase

let foods = ["oranges", "pears", "peaches"];

const convertToUppercase = (array) => {
    let converted =[]
    array.map((element) =>
        converted.push((element.toUpperCase()))
    );

    return converted;
};

console.log(convertToUppercase(foods));

This will help, thanks

about 4 years ago · Juan Pablo Isaza Report

0

const foods = ['oranges', 'pears', 'peaches']

const toUpper = s => s.toUpperCase()

console.log(foods.map(toUpper))

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!