I am looping through an array, in my loop i have this function that sets the array item id to localstorage
<% if (result.length > 0) { %>
<%result.map((item,index) => { %>
<% function check() {
localStorage.setItem("product_id", item.id);
}%>
<a onclick='check()' href="#">
<span>Edit</span>
</a>
<% }) %>
<% }
This is where an calling the function, still inside the loop
<a onclick='check()' href="#">
<span>Edit</span>
</a>
I want onclick of this anchor tag to call that function at the top, but its giving me this error
products:329 Uncaught ReferenceError: check is not defined
at HTMLAnchorElement.onclick (products:329)
onclick @ products:329