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
<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));