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

  • SEARCH
  • Home
  • 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 6234173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:26:13+00:00 2026-05-24T10:26:13+00:00

The template {{each}} directive works great for iterating over an array like this: var

  • 0

The template {{each}} directive works great for iterating over an array like this:

var myArray = ["a","b","c"];

I’m wondering if there is an equivalent for iterating over object properties, i.e.:

var myObj = {"propOne": "a", "propTwo": "b", "propThree": "c"};

I’d like a template that would let me output as

<ul>
  <li><span>propOne</span><span>a</span></li>
  .... etc

For bonus points I’d like to use this template from KnockoutJS.

  • 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-24T10:26:14+00:00Added an answer on May 24, 2026 at 10:26 am

    Actually {{each}} will walk through properties on an object. You can do something like this:

    {{each(prop, val) myObj}}
          <li><span>${prop}</span> - <span>${val}</span></li>
    {{/each}}
    

    Here is a sample in Knockout: http://jsfiddle.net/rniemeyer/rpMsM/

    If you really want to use the foreach option of the template binding, then the only real option is to map the object to an array of objects with key/value properties. Something like this: http://jsfiddle.net/rniemeyer/rpMsM/1/

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

Sidebar

Related Questions

I have this code which will include template.php file from inside each of these
Currently I have this code which calls the user template for each user node.
i have two files:(localhost/template/) index.php template.php each time when i create an article(an article
I have a template that creates a unique identifier for each type it is
I've got listbox that employs an item template. Within each item in the list,
I am having an issue with jQuery templates. I have a simple template each
Is there a subtle trick for template specialization so that I can apply one
I would like to apply a XSL template to a portion of the XML
function calcTotalScore(){ var arr = [A,B,C,D,E,F]; $.each(arr, function(n,val){ calcTotal(val); }); } calcTotal(value){ // sample
Is it possible to define a different 'Default Template' for each parent section on

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.