title: JSObject to JSArray
body: <p>I'm trying to read all URLs from a html document.</p>
  
  <p>I am using the following code:</p>
  
  <pre><code>    Dim html As String =
                                      "var linksArray = new Array(); " &amp;
                                      "for (var i = 0; i &lt; document.links.length; i++) {" &amp;
                                      "linksArray[i] = [String(document.links[i].innerHTML), String(document.links[i].innerText), String(document.links[i].href)];" &amp;
                                      "} " &amp;
                                      "return linksArray;"
  
      Try
          Dim linksArray As JSObject = _Browser.WebView.EvalScript(String.Format("(function(){{ {0} }})()", html))
  
          If linksArray Is Nothing Then
              Stop 'this line is not reached, so it should be fine so far
          End If
  
          'the following line throws an error
          Dim urls As JSArray = linksArray.ToArray()
  
          For Each link As JSObject In urls
              Dim sInnerHTML As String = link(0).ToString().Trim()
              Dim sInnerText As String = link(1).ToString().Trim()
              Dim sHRef As String = link(2).ToString().Trim()
  
              If sHRef &lt;&gt; "undefined" Then
  
                  Dim nItem As New clsURL
                  nItem.HRef = sHRef
                  nItem.InnerHTML = sInnerHTML
                  nItem.InnerText = sInnerText
  
                  nList.Add(nItem)
              End If
  
          Next
      Catch ex As Exception
          Debug.Print(ex.Message.ToString)
          Stop
      End Try
  </code></pre>
  
  <p>However, the line</p>
  
  <pre><code> Dim urls As JSArray = linksArray.ToArray()
  </code></pre>
  
  <p>throws the error "The object reference was not set to an object instance".</p>
  
  <p>Does anybody know how to do it correctly?</p>
  
  <p>Thank you!</p>
  
  <p><a href="https://i.stack.imgur.com/g3mnC.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/g3mnC.jpg" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/00ClC.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/00ClC.jpg" alt="enter image description here"></a></p>