Home > Back-end >  Captialized names and remove underscore from API drop down list appscript?
Captialized names and remove underscore from API drop down list appscript?

Time:12-09

I am able to get API fields on the front end HTML field box dropdown successfully.

I want achieve Account Currency instead of account_currency on the front end. How can I acheive that.

Code.gs

var ACCOUNTDATA = {
    adAccountUIFields: ['account_currency', 'account_id', ...... ]

}

html

<select id="fieldsData">
  
<? var data = ACCOUNTDATA.adAccountUIFields ?>
 <? if (data.length > 0) { ?>
<? for (i=0; i<data.length; i  ) { ?>
 <option value="<?= data[i] ?>"><?= data[i] ?></option>
   <? } ?>
 <? } ?>

   </select>

CodePudding user response:

  • Use split to separate the strings between _.
  • Use map, replace and toUpperCase to capitalize the first letter in each word.
  • Use join to join the words back to a single string, with blank spaces in between.
const updatedData = data[i].split("_")
                           .map(word => word.replace(/./, i => i.toUpperCase()))
                           .join(" ");
  • Related