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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:16:50+00:00 2026-06-05T17:16:50+00:00

From this post : I would first suggest that you optimize your dependentObservable (a.k.a.

  • 0

From this post:

I would first suggest that you optimize your dependentObservable (a.k.a. computed). When
you read any observable, Knockout registers a dependency to it in
Dependency Manager…

I can see in your pseudo-code that you are accessing this.ParentList()
in the while loop. It means registerDependency will be called 3000
times and the dependencies array will be scanned 3000 times, which is
bad for IE (since it has no built-in Array.indexOf method).

So my number one suggestion would be: Read all observables before
loops.

With this good advice in mind, here’s my question:

Is it bad form to iterate through observable arrays with ko utility methods (like the following)? [assume that this.mySelectListItems() is an observableArray]:

self.selectedValuesCount = ko.computed(function () {
    var total = 0;
    ko.utils.arrayForEach(this.mySelectListItems(), function (item) {
        if (item.selected() === true) {
            total += 1;
        }
    });
    return total;
}, self);

In other words, is there anything to be gained by doing the following?

self.selectedValuesCount = ko.computed(function () {
    var total = 0;
    var myArray = this.mySelectListItems();
    ko.utils.arrayForEach(myArray, function (item) {
        if (item.selected() === true) {
            total += 1;
        }
    });
    return total;
}, self);
  • 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-05T17:16:52+00:00Added an answer on June 5, 2026 at 5:16 pm

    No, those bits of code are perfectly equal.

    You would only gain a performance boost if you’d retrieve the value of the same observable again and again in the callback that you hand over to arrayForEach – but in this case, the value of the observable array gets retrieved just once, so there is no point why you would want to put that array in an extra variable.

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

Sidebar

Related Questions

This post from F# News states that F# can inline a function passed as
Should be an easy one. I thought, from reading this blog post that I
I would like to continue the discussion from this post: GPX Schema validation problems
This is my first ever post on any forum, so excuse my etiquette. Im
I learnt from this post here to create helper functions in namespace. 'Helper' functions
All are from this post . What does these statement mean: error(nargchk(5, 6, nargin));
I'm trying to implement the ringbuffer from this post https://stackoverflow.com/a/827749 and the only code
I've seen a plugin for Vim called AutoClose (discovered from this post) which automatically
I've installed NVM for node.js using the instructions from this post: http://www.backdrifter.com/2011/02/18/using-nvm-and-npm-to-manage-node-js/ When I
For some time I am worknig in MVC, I learnt from this post, http://evolpin.wordpress.com/2011/04/12/asp-net-mvc-partialview-with-ajax/#comment-435

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.