javascript - remove - n.fn.init to array

Jquery is adding prevObject: to array (2)

I want to sum all floats in an array

when I do this in the chrome console

{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

    row = $(this).find('')
     return parseFloat($(v).attr("data-time"))})));

('') 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?

The return type of calling map on a jQuery collection is another jQuery collection. If you want to access just the results of the function used in the map, you need to use .toArray() to return the underlying array instead:

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

This should carry out the expected result:

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

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.