There is HTML text in which there are several [] .

There is also an array of this type:

 [[1,2], [3,4], [5,6]] 

That is, a corresponding array should be inserted (by index) into each “block” [] in the text.

Please help me realize this (without jquery), otherwise it doesn't work for me. The maximum that I have achieved is that I received an array of “blocks” [] , but I can’t replace them in the text in any way in order to get the source text with the replacement.

Closed due to the fact that the essence of the issue is incomprehensible by the participants Alexey Shimansky , andreymal , Gleb Kemarsky , Komdosh , Eugene Krivenja October 31 '17 at 9:31 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 2
    did not understand anything at all ... put the code ... - Air

1 answer 1

It's simple:

 let arr = [[1,2], [3,4], [5,6]], pointer = 0; let wrapper = document.querySelector('div'); wrapper.innerHTML = wrapper.innerHTML.replace(/\[\]/g, _ => (_ = arr[pointer].toString(), pointer++, _)); 
 span{ background: #efefef; padding: 3px; } 
 <div>Это первый массив: <span>[]</span>, тут уже второй: <span>[]</span><br /> А это третий: <span>[]</span></div> 


For the future - try to lay out their work, but it looks like begging, and not a request to help.