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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:54:38+00:00 2026-06-02T13:54:38+00:00

underscore.js is handling the templating on the page, and I have jQuery on my

  • 0

underscore.js is handling the templating on the page, and I have jQuery on my page also.

I have an array that looks something like this:

orders = [{q:5},{q:5},{q:5},{q:5},{q:5}];

Now on the page I want the sum of q printed, but I cannot get it to work.

I tried a lot of code snippets, but none of them seem to work. The one I thought had do work is this one:

<td><% print( _.reduce(orders.q), function(memo, num){ return memo + num; }, 0 ) %></td>

It’s from the page of underscore itself.

This piece of code gives me:

undefined is not a function;
  • 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-02T13:54:38+00:00Added an answer on June 2, 2026 at 1:54 pm

    orders.q looks for a property q on the array orders — so orders.q is most likely returning undefined, which is indeed not a function.

    You probably want to pass _.pluck(orders, 'q'), which returns an array of the values of q for each item in orders, to _.reduce. And double-check your parentheses:

    _.reduce(orders.q, function(memo, num){ return memo + num; }, 0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the underscore.js templating function and have done a template like this: <script
I use underscore.js for HTML Templating, set to use mustache syntax, like this: {{
I am using underscore.js's templating capabilities from backbone.js, I have the following template that
I would like to select all records that have an underscore character in their
I'm using backbone's underscore templating engine with the mustache formatting patterns. I have already
It looks like XStream (com.thoughtworks.xstream -> xstream 1.4.2) is handling underscores in element and
How do I escape the underscore character? I am writing something like the following
Armed with underscore , I could achieve something fantastic like below: _([1,2,3]).chain().map(function(n) {return n*2}).reduce(function(m,a)
I want to use underscore function in jade template, like this p= _.keys(user) Not
I am trying to escape the underscore character in a LIKE Statement. I have

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.