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

  • Home
  • SEARCH
  • 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 9083441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:46:40+00:00 2026-06-16T20:46:40+00:00

I want to sum all floats in an array when I do this in

  • 0

I want to sum all floats in an array

when I do this in the chrome console

$("tr.project_hours").find("td.number").map(function(i,v)
{return parseFloat($(v).attr("data-time"))
})

I get

[0, 0, 0, 0, 0, 0, 0]

This is what I want

But, in my code I have more $(“tr.project_hours”) and I want to sum them separately.
So, I do

$("tr.project_hours").each(function(){
    row = $(this).find('td.total')
    row.html(sumInputsIn($(this).find("td.number").map(function(i,v){
     return parseFloat($(v).attr("data-time"))})));
    })

(‘td.total’) is the column where the result should be displayed. The problem is that the last code returns this in the console

[0, 0, 0, 0, 0, 0, 0, prevObject: jQuery.fn.jQuery.init[7], context: <tr>]

So the result is the notorious NaN.

Why do I get the prevObject in my array? And how can I refactor to get rid of it?

  • 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-16T20:46:41+00:00Added an answer on June 16, 2026 at 8:46 pm

    This should carry out the expected result:

    $("tr.project_hours").each(function(index, element) {
        var row = $(this).find('td.total');
        var total = 0;
        $(this).find("td.number").each(function (index, element) {
            total += parseFloat($(v).attr("data-time"));
        });
        row.html(total);
    });
    

    jQuery map performs for (item in array) which apparently does not filter by hasOwnProperty() if you are getting those keys. In this case you need to write the logic yourself I guess.

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

Sidebar

Related Questions

I've got this query and I want to SUM all the results of the
I've got the following 2d array and I want to sum all of the
I want to sum all elements of matrix in Matlab. If I had a
Crazy question...however, I want the sum of all the rows in a table for
I want to sum columns. In my controller def index @performance_reports = PerformanceReport.all end
What I want to do is to sum values of a field in all
I want to find the sum and count of specific values in my table.
I have a while loop like below. I want to sum all of the
I want to sum all elements (e.g. price) from table column where some values
I am trying to show a sum of the floats of all records entered,

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.