Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7400591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:16:17+00:00 2026-05-29T04:16:17+00:00

How can I output <hr> after every iteration except last one with mustache.js. I

  • 0

How can I output <hr> after every iteration except last one with mustache.js. I tried javascript for loop but I couldn’t get rid of last <hr>. (Some people suggest using handlebars.js but I would like stay with mustache.)

Here is my json (the list gets bigger as more employees get added)

    {
      employees: [
        {firstName: "John", lastName: "Smith"},
        {firstName: "John", lastName: "Doe"},
        {firstName: "Jane", lastName: "Doe"}    
       ]
    }

I want this html output:

John Smith
<hr>
John Doe
<hr>
Jane Doe
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:16:17+00:00Added an answer on May 29, 2026 at 4:16 am

    Looking at the Mustache Manual, you’ll want to use what’s referred to as “Inverted Sections”. From the manual:

    An inverted section begins with a caret (hat) and ends with a slash.
    That is {{^person}} begins a “person” inverted section while
    {{/person}} ends it.

    While sections can be used to render text one or more times based on
    the value of the key, inverted sections may render text once based on
    the inverse value of the key. That is, they will be rendered if the
    key doesn’t exist, is false, or is an empty list.

    To utilize this, you could add an extra attribute to the last employee to distinguish it.

    JSON:

    {
      "employees": [
        {"firstName": "John", "lastName": "Smith"},
        {"firstName": "John", "lastName": "Doe"},
        {"firstName": "Jane", "lastName": "Doe", "last": true}    
       ]
    }
    

    Mustache Template:

    {{#employees}}
      {{firstName}} {{lastName}}
      {{^last}}
        <hr />
      {{/last}}
    {{/employees}}
    

    This is very similar to what the Mustache Demo showcases, using the “first” attribute on the first object in the array of colors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone tell me why I always have this strange output after running this
I can output a locale sensitive time format using strftime('%X') , but this always
How can I get output from Java anonymous classes? In .Net I would use
How can I insert to a string comma (,) after every 3 position starting
Edit: After getting five downvotes but no comments saying anything about why, I've tried
I couldn't get the output also couldn't find the problem. Question: Table : rent_info(cust_id,date_out,date_due_in,date_returned,fine)
How can I explode a string at the position after every third semicolon (;)?
EDITED: is there a way i can use <BR> after every comma(,) ? <asp:SqlDataSource
I trying to find function in PHP that can output the binary data. The
How can I output all of the text in a node, including the text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.