D3.js selection.nodes() Function

The selection.nodes() function in D3.js is used to return the array of selection that contains HTML elements.
Syntax:
selection.nodes()
Parameters: This function does not accept any parameters.
Return Values: This function returns an array of elements.
Example 1:
HTML
| <!DOCTYPE html> <htmllang="en">  <head>     <metacharset="UTF-8">     <metaname="viewport"path1tent=         "width=device-width,initial-scale=1.0">     </script>     <scriptsrc=     </script> </head>  <body>     <div>Some text</div>     <div>Geeks for zambiatek</div>     <div>Geeks for zambiatek</div>     <div>Some text</div>      <script>         let selection = d3.selectAll("div")         console.log(selection.nodes())     </script> </body>  </html>  | 
Output:
Example 2: When nested containers are given and selection is empty.
HTML
| <!DOCTYPE html> <htmllang="en">  <head>     <metacharset="UTF-8">     <metaname="viewport"path1tent=         "width=device-width,initial-scale=1.0">     </script>     <scriptsrc=     </script> </head>  <body>     <div>Some text</div>     <div>Geeks for <div>zambiatek</div>     </div>     <div>Geeks <div></div> for zambiatek</div>     <div>Some text</div>      <script>         let selection = d3.selectAll("div")         console.log(selection.nodes())         selection = d3.selectAll("h2")         console.log(selection.nodes())     </script> </body>  </html>  | 
Output:

 
				 
					


