Create array with Array.from - Javascript Array

Javascript examples for Array:from

Description

Create array with Array.from

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//w  w  w.  j av  a  2  s.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>

Related Tutorials