1

I have a html markup like this :

 <div>
   <p> My name is {{ name }} </p>
   <p>I learn {{ lang }} </p>
   <p>I am a {{ prof }} </p>
<div>

I want a javascript function that can identify all the words inside the mustache braces and arrange them with commas. I assume it will look something like this :

 arrange("div"); // name, lang, prof
 // Output should not be in array
// i.e. [ name, lang, prof ] 

Output may be in string ! Can this be done without any external framework ?

Debarchito
  • 1,305
  • 7
  • 20
  • 1
    Don't you have access to those variables where you render the template? You should be able to build your string there without having to get anything from the DOM. – JDunken Oct 17 '19 at 15:38
  • 1
    I am new to javascript, please add an example – Debarchito Oct 17 '19 at 15:39
  • 1
    If the output is an array, just convert it to a string with `.join()`, like in `["name", "lang", "prof"].join(",")`, which would be `"name,lang,prof"` – Radvylf Programs Oct 17 '19 at 15:46

0 Answers0