I have this scenario, but it's not working...
Under h1 I want to show all elements from my array and in input value I want to show the last element from my array:
<h1>Solutions></h1>
<% var element = title.forEach(function(item) { %>
<p><%= item.name%></p>
<% }) %>
<form action="/" method="post">
<input type="text" name="name" />
<input type="text" name="s" placeholder="solution subtitle"
value=
<%= element.length-1 %>
/>
<button type="submit" name="submit">Submite</button>
</form>
How can I get the last element from array using eJS?
array[array.length - 1]. Are you trying to get the last element of thetitleorelementarray?titile[titile.length - 1]. In the input element, that would be something like this:<input type="text" name="s" placeholder="solution subtitle" value= <%= titile[titile.length - 1]%>