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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:36:42+00:00 2026-06-16T17:36:42+00:00

I am currently putting together a simple application for inventory management using backbone. I

  • 0

I am currently putting together a simple application for inventory management using backbone. I have a table in my database that contains model and quantity; this is the strigify version of the object:

var invt =

[
{
“id”:1,
“model”:”Canon SX230″,
“qty”:10,
“price”:”150.50″
},
{
“id”:2,
“model”:”Canon Rebel T3i”,
“qty”:25,
“price”:”450.50″,
},
{
“id”:3,
“model”:”Canon Rebel T2″,
“qty”:10,
“price”:”250.00″
},
{
“id”:4,
“model”:”Canon Rebel T2i”,
“qty”:15,
“price”:”275.00″
},
{
“id”:5,
“model”:”Canon SX230″,
“qty”:5,
“price”:”125.00″
}]

How can I filter through to sum the quantities based on the model. Creating a new object with the similar models totaled quantity.

Essentially the result would be:
[{
“id”:1,
“model”:”Canon SX230″,
“qty”:15,
“price”:”275.00″
},
{
“id”:2,
“model”:”Canon Rebel T3i”,
“qty”:25,
“price”:”450.50″
}]
etc…

I’ve been trying to use the following loop:

var sum = {};

    for (var i = 0; i < invt.length; i++) { 
        var record = invt[i];

        sum.model = record.model + (sum.model);
    };
  • 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-16T17:36:44+00:00Added an answer on June 16, 2026 at 5:36 pm

    As you’ve used only JS related tags, I guess you want to do this client-side.

    You can do it like this:

    var records = [
        {
            id: 1,
            model: "A",
            quantity: 6
        }, {
            id: 1,
            model: "A",
            quantity: 4
        }, {
            id: 1,
            model: "B",
            quantity: 3
        }, {
            id: 1,
            model: "B",
            quantity: 2
        }
    ];
    
    var sum = {};
    for(var i = 0; i < records.length; i++) {
        var record = records[i];
        sum[record.model] = record.quantity + (sum[record.model] || 0);
    }
    document.body.innerHTML = JSON.stringify(sum);​
    

    Demo: http://jsfiddle.net/Dhsm5/

    It would be trivial to convert this object into the format you want.

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

Sidebar

Related Questions

I am currently putting together a demo application that needs to show 28,000 markers
I am currently putting together some jQuery that will activate slideDown() when an element
little background: currently putting together a website that is selling products, many of which
I'm working on putting together a simple POC app using Fluent NHibernate to attempt
I'm currently putting together (on old fashioned paper) a layout for my new database,
I'm currently putting together a processing script for a website, and have run into
I'm putting together a WCF service that handles a large search (currently 50-60 parameters,
I'm putting together a fixed, one-page site that deploys an overlay using jQuery. There
I am putting together a simple networking site and would like to have the
I'm putting together a little application that involved both a GUI, HTTP and TCP

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.