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

142
Views
In JS for loop how substitute letter, 'a' in string 'begin_a_end' w/ array element, e.g., 'begin_vowe[i]_end'?

In a javascript for loop, I need to substitute the underscore bounded a with Vowels[i] and the quote bounded ā with MacronVowels[i] in:

flosType_a_withMacron()
putMacronedLetter("ā")

I am trying to condense a series of five functions with vowels a,b,c,d,e and ā,ē,ī,ō,ū by creating 2 arrays (see code) and replacing (in the for loop) the function with aforesaid array elements. Obviously this will only save me a few lines of code but I relatively new to coding and just want to know how to do this for learning purposes.

Here are the five functions as they current exist and work correctly. What I want to do in wrap them into one in a for loop:

EXISTING CODE:

        function type_a_withMacron() {
                    putMacronedLetter("ā");
                    moveCursorToEnd(element);
        }               
        function type_e_withMacron() {
                    putMacronedLetter("ē");
                    moveCursorToEnd(element);
        }                                   
        function type_i_withMacron() {
                    putMacronedLetter("ī");
                    moveCursorToEnd(element);
        }
        function type_o_withMacron() {
                    putMacronedLetter("ō");
                    moveCursorToEnd(element);
        }
        function type_u_withMacron() {
                    putMacronedLetter("ū");
                    moveCursorToEnd(element);
        }

PROPOSED CODE: (what is proper formatting here, this is obv wrong, just asking)

const flos_Vowels = ["a","b","c","d","e"];
const flos_MacronVowels = ["ā","ē","ī","ō","ū"];
       
for(let i = 0;i < 5;i++ )
{
    function flosType_flos_[Vowels[i]]_withMacron()
    {
        putMacronedLetter("[flos_MacronVowels[i]]");
        moveCursorToEnd(element);
    }
}
about 4 years ago · Santiago Gelvez
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!