Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to correctly write multiple meta tag using JS?

Helo, I’m very raw in JS. I want to ask about my code, how to write it correctly?

function impScript(scriptURL){
   let headTitle = document.querySelector('head');
   let setProperty = document.createElement('script');
   setProperty.setAttribute('href',scriptURL);
   headTitle.appendChild(setProperty);
}
const metaScript = ['ar.js','ar2.js']
impScript(metaScript);

the code is working, but it resulting

<script href="ar.js,ar2.js"></script>

I’m hopping to make it like this

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<script href="ar.js"></script>
<script href="ar2.js"></script>

how can I do it?
your answer will be very helpful, thank you.

>Solution :

You need to iterate through the array and create the tag one by one:

metaScript.forEach(s => impScript(s));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading