Correct use of JavaScript to write multiple meta tags
P粉432906880
2023-08-01 14:50:44
<p>Hello, I am very new to JS. I would like to ask about my code, how can I write it correctly?</p>
<pre class="brush:php;toolbar:false;">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);</pre>
<p>The code works, but the result is 2script href="ar.js,ar2.js"></script></p>
<p>I want to do this</p>
<pre class="brush:php;toolbar:false;"><script href="ar.js"></script>
<script href="ar2.js"></script</pre>
<p>What should I do? Your answer will be helpful, thank you. </p>
You need to loop through the array and create tags one by one: