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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:06:49+00:00 2026-06-16T02:06:49+00:00

I have an observable array var myArray = ko.observableArray([ { name: Jimmy, type: Friend,

  • 0

I have an observable array

var myArray = ko.observableArray([
      { name: "Jimmy", type: "Friend", Age: 30 },
      { name: "George", type: "Friend", Age: 40 },
      { name: "Zippy", type: "Enemy", Age: 20 }
    ]);

Now I want my output as

Friend Total Age: 70

Jimmy 30
George 40

Enemy Total Age : 20

Zippy 20

There is a similar jsfiddle link

  • 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-16T02:06:50+00:00Added an answer on June 16, 2026 at 2:06 am

    If you want to keep with the generic structure (not just create computeds directly for “FriendTotalAge” and “EnemyTotalAge”), then you could expand the distinct extension to include a property to use for the total.

    For example, you could pass in the name of the property that you want to use as a total and add a section in the extension like:

        if (totalProp) {
            for (key in propIndex) {
                if (propIndex.hasOwnProperty(key)) {
                    propIndex[key].total = ko.computed(function() {
                        var total = 0;
                        ko.utils.arrayForEach(propIndex[key], function(item) {
                            total += parseInt(ko.utils.unwrapObservable(item[totalProp]), 10) || 0;
                        });  
    
                        return total;                        
                    });
                }                    
            }
        }  
    

    Now, your index could be by “type” and contain a computed total of the “age” property.

    Update of the fiddle here: http://jsfiddle.net/rniemeyer/yrh5D/

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

Sidebar

Related Questions

I have an observable array with var items= [ {image: /images/image1.jpg }, {image: /images/image2.jpg
I have a viewModel: var teamViewModel = { teams: ko.observableArray([]), selectedTeam: ko.observable(1), clearTeams: function(){
Inside my viewmodel I have following code: var self = this; self.Name = ko.observable(data.Name);
I have an observableArray, I have a name "Zippy", I need to check if
I have a Knockout observable array that I wish to edit from within Javascript
I am new to Knockout.js, I have created an observable array and initialized with
I have a an array of observable collections and I want to display all
I have an observable array of a complex object. The initial load is fine,
I have a modelView that looks like that: var teamViewModel = { teams: ko.observableArray([]),
I have an observable array containing objects (dynamically created) that have themselves observable attributes.

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.