I have the string "some kind of text", and depending on the length of the arr array, I want to copy this string as many times. For example:

 var str = "<span>some text</span>"; var arr = [{name:'John'}, {name:'Bill'},{name:'Clara'}]; // length = 3; 

so that the string str becomes var str = "<span>some text</span><span>some text</span><span>some text</span>"; . Tell me how to do it better? There are descriptions for copying objects, etc., but for strings I could not find it ..

UPD: working with DOM is not needed, that is, you need to either str be "bigger" depending on the length of the array, or create a new variable. In the DOM it will not go ..

    1 answer 1

     document.querySelector('#result').innerHTML = "<span>some text</span>".repeat([{name:'John'}, {name:'Bill'},{name:'Clara'}].length); 
     <div id='result'></div> 

    • thank! str.repeat (arr.length) - helped! - YoroDiallo