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

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현