title: How to check in loop whether test function applies to array index value
body: <p>I have an array stored in the local storage, I fetch it on browser load and this is what I do when I fetch it:</p>
  <p>The way this code supposed to work is if the index fetched has the speciation applied to it then it will be treated as a link, if not it will be treated as a text. I used the same method for the input value and it worked but can't seem to get it to work here:</p>
  <pre><code>if (leadsFromStorage) {
    //^leads from storage isnt empty
    myLeads = leadsFromStorage;
    console.log(myLeads)
    let listItems = &quot;&quot;;
    listItems = document.createElement(&quot;li&quot;)
    for (i = 0; i &lt; myLeads.length; i++) {
      if (test(myLeads[i]) === true)
      {
        listItems.innerHTML = `
          &lt;li&gt;
            &lt;a target='_blank' href='${myLeads}'&gt;
                ${myLeads}
            &lt;/a&gt;
          &lt;/li&gt;
          `;
        listEl.appendChild(listItems)
      }
      else {
        listItems.innerHTML = `
              &lt;li&gt;
              
                    ${myLeads}
                
              &lt;/li&gt;
              `;
        listEl.appendChild(listItems)
      }
    }
    console.log(&quot;storage isnt empty&quot;);
  }
  </code></pre>
  <p>this is the test function</p>
  <pre><code>function test(input) {
    const expression = /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&amp;//=]*)?/gi;
    const regex = new RegExp(expression);
    if (input.match(regex)) {
      return true
    } else {
      return false
    }
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/Spmus.jpg" rel="nofollow noreferrer">I want it to look like this</a>:</p>
  <p><a href="https://i.stack.imgur.com/Spmus.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Spmusm.jpg"></a></p>
  <p><a href="https://i.stack.imgur.com/KLQmk.jpg" rel="nofollow noreferrer">but instead it looks like this</a>:</p>
  <p><a href="https://i.stack.imgur.com/Spmusm.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KLQmkm.jpg"></a></p>
  <p>Any help please?</p>