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 8088337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:03:45+00:00 2026-06-05T19:03:45+00:00

Given this plain JavaScript construct: var MyObject = function() { var privateArray = [

  • 0

Given this plain JavaScript construct:

var MyObject = function() {
  var privateArray = [
    { name: 'one' },
    { name: 'two' }
  ];
  this.returnPrivate = function(index) {
    return privateArray[index];  
  };
};
var obj = new MyObject();

Within a handlebars template I would like to be able to print the name property of an object at a particular index of the privateArray using the returnPrivate function.

// This of course does not work.
<p>{{returnPrivate(1).name}}</p>

I am just starting out with handlebars.js, so there might already be a standard way of doing this. Or this might be trying to build too much logic into the template and be going against what handlebars is all about.

  • 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-06-05T19:03:46+00:00Added an answer on June 5, 2026 at 7:03 pm

    I have come up with a Helper that does what I need it to, but I would very much appreciate some feedback as to whether this is the best way to solve this type of problem with Handlebars.

    /**
     * Given the name of a function that returns an array value, this helper
     * returns the value at a given index.  Optionally it takes a property name
     * in case the array value at the given index is itself an object.
     */
    Handlebars.registerHelper('eqf', function(func, index, prop) {
      if (typeof prop === 'string') {
        return func(index)[prop];
      } else {
        return func(index);
      }
    });
    

    Usage for question example:

    <p>{{eqf returnPrivate 1 "name"}}</p>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to return a plain javascript if a user access to a given
Given this markup: // Calendar.html?date=1/2/2003 <script> $(function() { $('.inlinedatepicker').datepicker(); }); </script> ... <div class=inlinedatepicker
Given this XML: <?xml version=1.0 encoding=utf-8?> <content dataType=XML> <item type=Promotion name=Sample Promotion expires=04/01/2009> <![CDATA[
Given this code: var arrayStrings = new string[1000]; Parallel.ForEach<string>(arrayStrings, someString => { DoSomething(someString); });
I have this in Nginx configuration files gzip_types text/plain text/html text/css application/json application/x-javascript text/xml
Assembly.Location gives a plain path to the assembly. Unfortunately this is empty when running
Given this variable in tcsh: set i = ~/foo/bar.c how can I get just
Given this hash that comes though :params positions=>{ 1=>{x=>50, y=>30}, 2=>{x=>22, y=>53}, 3=>{x=>68, y=>35}
Given this object class Contact { public IEnumerable<Person> People { get; } public string
Given this Itemgroup: <ItemGroup> <Foo Include=First> <Value>1</Value> </Foo> <Foo Include=Second> <Value>2</Value> </Foo> </ItemGroup> How

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.