Vardan Hambardzumyan
Vardan Hambardzumyan

Reputation: 416

How to get the last element from array?

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?

Upvotes: 0

Views: 427

Answers (1)

Kawatare267
Kawatare267

Reputation: 4376

You may use like this

 <%= element[element.length-1] %>

Upvotes: 1

Related Questions