Running reduce() on jQuery collectionIs there an “exists” function for jQuery?Add table row in jQueryHow do I check if an element is hidden in jQuery?Setting “checked” for a checkbox with jQuery?How can I know which radio button is selected via jQuery?How to check whether a checkbox is checked in jQuery?Disable/enable an input with jQuery?How can I refresh a page with jQuery?jQuery scroll to element“Thinking in AngularJS” if I have a jQuery background?

What are the purposes of autoencoders?

Is this toilet slogan correct usage of the English language?

What is this called? Old film camera viewer?

How do I color the graph in datavisualization?

2.8 Why are collections grayed out? How can I open them?

Why can Carol Danvers change her suit colours in the first place?

Electoral considerations aside, what are potential benefits, for the US, of policy changes proposed by the tweet recognizing Golan annexation?

On a tidally locked planet, would time be quantized?

Lowest total scrabble score

Is it improper etiquette to ask your opponent what his/her rating is before the game?

C++ debug/print custom type with GDB : the case of nlohmann json library

copy and scale one figure (wheel)

How to indicate a cut out for a product window

The IT department bottlenecks progress. How should I handle this?

Should I outline or discovery write my stories?

What was this official D&D 3.5e Lovecraft-flavored rulebook?

How to explain what's wrong with this application of the chain rule?

What was the exact wording from Ivanhoe of this advice on how to free yourself from slavery?

Why electric field inside a cavity of a non-conducting sphere not zero?

Did arcade monitors have same pixel aspect ratio as TV sets?

Is it safe to use olive oil to clean the ear wax?

Drawing ramified coverings with tikz

What is the evidence for the "tyranny of the majority problem" in a direct democracy context?

Why is it that I can sometimes guess the next note?



Running reduce() on jQuery collection


Is there an “exists” function for jQuery?Add table row in jQueryHow do I check if an element is hidden in jQuery?Setting “checked” for a checkbox with jQuery?How can I know which radio button is selected via jQuery?How to check whether a checkbox is checked in jQuery?Disable/enable an input with jQuery?How can I refresh a page with jQuery?jQuery scroll to element“Thinking in AngularJS” if I have a jQuery background?













2















I'm working on an application and I have a collection of DOM objects where I want to sum their combined widths. I wanted to use the reduce() function for this.



The variable containing the jQuery collection is called menuItems and my attempt looks like this:



menuItems.toArray().reduce((total, item) => total += item.clientWidth);


But weirdly, that function returns this output:



// "http://localhost:3000/97689982"


Which is equivalent to all of the widths concatenated together in a string excluding the first element.



Running something like menuItems.toArray()[0].clientWidth correctly outputs the width of the first item.










share|improve this question
























  • What is the input data inside menuItems? can you post it here too?

    – varit05
    2 days ago















2















I'm working on an application and I have a collection of DOM objects where I want to sum their combined widths. I wanted to use the reduce() function for this.



The variable containing the jQuery collection is called menuItems and my attempt looks like this:



menuItems.toArray().reduce((total, item) => total += item.clientWidth);


But weirdly, that function returns this output:



// "http://localhost:3000/97689982"


Which is equivalent to all of the widths concatenated together in a string excluding the first element.



Running something like menuItems.toArray()[0].clientWidth correctly outputs the width of the first item.










share|improve this question
























  • What is the input data inside menuItems? can you post it here too?

    – varit05
    2 days ago













2












2








2








I'm working on an application and I have a collection of DOM objects where I want to sum their combined widths. I wanted to use the reduce() function for this.



The variable containing the jQuery collection is called menuItems and my attempt looks like this:



menuItems.toArray().reduce((total, item) => total += item.clientWidth);


But weirdly, that function returns this output:



// "http://localhost:3000/97689982"


Which is equivalent to all of the widths concatenated together in a string excluding the first element.



Running something like menuItems.toArray()[0].clientWidth correctly outputs the width of the first item.










share|improve this question
















I'm working on an application and I have a collection of DOM objects where I want to sum their combined widths. I wanted to use the reduce() function for this.



The variable containing the jQuery collection is called menuItems and my attempt looks like this:



menuItems.toArray().reduce((total, item) => total += item.clientWidth);


But weirdly, that function returns this output:



// "http://localhost:3000/97689982"


Which is equivalent to all of the widths concatenated together in a string excluding the first element.



Running something like menuItems.toArray()[0].clientWidth correctly outputs the width of the first item.







jquery ecmascript-6






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago









georgeawg

34.1k115370




34.1k115370










asked 2 days ago









funkylaundryfunkylaundry

78121123




78121123












  • What is the input data inside menuItems? can you post it here too?

    – varit05
    2 days ago

















  • What is the input data inside menuItems? can you post it here too?

    – varit05
    2 days ago
















What is the input data inside menuItems? can you post it here too?

– varit05
2 days ago





What is the input data inside menuItems? can you post it here too?

– varit05
2 days ago












1 Answer
1






active

oldest

votes


















4














You need to parse the client width from string to a number before reducing it.



const totalClientWidth = menuItems.reduce((acc, cur) => acc + Number(cur.clientWidth), 0);





share|improve this answer




















  • 1





    @TylerRoper fixed it.

    – Kunal Mukherjee
    2 days ago






  • 1





    Nice, thanks. Good answer :)

    – Tyler Roper
    2 days ago










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281442%2frunning-reduce-on-jquery-collection%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









4














You need to parse the client width from string to a number before reducing it.



const totalClientWidth = menuItems.reduce((acc, cur) => acc + Number(cur.clientWidth), 0);





share|improve this answer




















  • 1





    @TylerRoper fixed it.

    – Kunal Mukherjee
    2 days ago






  • 1





    Nice, thanks. Good answer :)

    – Tyler Roper
    2 days ago















4














You need to parse the client width from string to a number before reducing it.



const totalClientWidth = menuItems.reduce((acc, cur) => acc + Number(cur.clientWidth), 0);





share|improve this answer




















  • 1





    @TylerRoper fixed it.

    – Kunal Mukherjee
    2 days ago






  • 1





    Nice, thanks. Good answer :)

    – Tyler Roper
    2 days ago













4












4








4







You need to parse the client width from string to a number before reducing it.



const totalClientWidth = menuItems.reduce((acc, cur) => acc + Number(cur.clientWidth), 0);





share|improve this answer















You need to parse the client width from string to a number before reducing it.



const totalClientWidth = menuItems.reduce((acc, cur) => acc + Number(cur.clientWidth), 0);






share|improve this answer














share|improve this answer



share|improve this answer








edited 2 days ago

























answered 2 days ago









Kunal MukherjeeKunal Mukherjee

1,80121026




1,80121026







  • 1





    @TylerRoper fixed it.

    – Kunal Mukherjee
    2 days ago






  • 1





    Nice, thanks. Good answer :)

    – Tyler Roper
    2 days ago












  • 1





    @TylerRoper fixed it.

    – Kunal Mukherjee
    2 days ago






  • 1





    Nice, thanks. Good answer :)

    – Tyler Roper
    2 days ago







1




1





@TylerRoper fixed it.

– Kunal Mukherjee
2 days ago





@TylerRoper fixed it.

– Kunal Mukherjee
2 days ago




1




1





Nice, thanks. Good answer :)

– Tyler Roper
2 days ago





Nice, thanks. Good answer :)

– Tyler Roper
2 days ago



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281442%2frunning-reduce-on-jquery-collection%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript