1

I have an array of values and object of key-value pairs:

var array = ["first", "second"];
var object = {
    "first":"firstvalue",
    "second":"secondValue"
};

I would like to iterate through array and base on the value, pick the value from the object, something like this (I know this doesn't work, but I'm looking at similar approach):

{{#array}}
    <tr><td>{{.}}</td><td>{{object[.]}}</td></tr>
{{/array}}

So that output would be:

<tr><td>first</td><td>firstvalue</td></tr>
<tr><td>second</td><td>secondValue</td></tr>

1 Answer 1

1

I don't think that's possible as Mustache is "logic-less". Perhaps you can try swapping out Mustache with Handlebars

Handlebars is largely compatible with Mustache templates. In most cases it is possible to swap out Mustache with Handlebars and continue using your current templates.

with handlerbars, you can create helpers to handle the logic.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.