Javascript examples for Array Operation:Array Element
Push all html-paragraphs from a string to a new array
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){/*from w ww. ja va 2s . c om*/ let string = `<p>Hi, my name is Test!</p> <div class="xyz">This is a div</div> <p>This is a test!</p> <p>TEST TEST TEST!</p>`; let div = document.createElement("div"); div.innerHTML = string; let newString = Array.from(div.querySelectorAll("p"), p => p.outerHTML); console.log(newString); } </script> </head> <body> </body> </html>