Create a new lis in an array and then sum their valuesCreate GUID / UUID in JavaScript?Create ArrayList from arrayHow do I check if an array includes an object in JavaScript?How to append something to an array?Sort array of objects by string property valueLoop through an array in JavaScriptHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?Copy array by valueFor-each over an array in JavaScript?

Is there any difference between "result in" and "end up with"?

How can I perform a deterministic physics simulation?

On the consistency of different well-polished astronomy software

Volcanic 3D masyu

how to change dot to underline in multiple file-names?

Why do my fried eggs start browning very fast?

Did Logical Positivism fail because it simply denied human emotion?

Based on what criteria do you add/not add icons to labels within a toolbar?

If someone else uploads my GPL'd code to Github without my permission, is that a copyright violation?

Why does capacitance not depend on the material of the plates?

Magento 2 Is it possible to use same event in multiple Modules?

Does one say "Shehecheyanu" on haadama fruit?

Using Forstner bits instead of hole saws

How to win against ants

Is a switch from R to Python worth it?

What could prevent players from leaving an island?

What printing process is this?

How long should I wait to plug in my refrigerator after unplugging it?

Broken bottom bracket?

How do I show and not tell a backstory?

Is there a booking app or site that lets you specify your gender for shared dormitories?

On an ADS-B In display, do the pilots see the squawk code or call sign for other aircraft?

Curious to know reasons, why Aura is not allowed in LWC

Piece de Resistance - Introduction & Ace and A's



Create a new lis in an array and then sum their values


Create GUID / UUID in JavaScript?Create ArrayList from arrayHow do I check if an array includes an object in JavaScript?How to append something to an array?Sort array of objects by string property valueLoop through an array in JavaScriptHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?Copy array by valueFor-each over an array in JavaScript?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-2















My team is working on a web application to display personal finances.
We would like the user to add their spendings with the matching category (e.g. $50 for food) and make those entries lis. We then want to take the sum of, for example, all the food entries and display it. So we need to somehow get those lis in arrays - that's what I think. And somehow the new lis, which are not there yet, must have some special id (?) so they "find" each other (meaning, all food values go to the food array)? And is there a way to do it with React?



I'm not sure how to integrate React and how to form arrays to sum the values (here "wert") later.



  Kategorie hinzufügen: add category

  Zahlenwert hinzufügen: add value

  dropdown: where you can choose categories

  wert: where you insert the spent value

  eingabeNum: insertedNum

  eingabeText: insertedText



function grab(event) 
if (event.which === 13)










share|improve this question





















  • 1





    Looks like you are using Jquery instead of react. And your question is not really clear to me. What do you mean by create new lis in an array? What is lis?

    – Hung Cao
    Mar 26 at 18:13











  • i think, it's all <li> elements.

    – Nina Scholz
    Mar 26 at 18:20

















-2















My team is working on a web application to display personal finances.
We would like the user to add their spendings with the matching category (e.g. $50 for food) and make those entries lis. We then want to take the sum of, for example, all the food entries and display it. So we need to somehow get those lis in arrays - that's what I think. And somehow the new lis, which are not there yet, must have some special id (?) so they "find" each other (meaning, all food values go to the food array)? And is there a way to do it with React?



I'm not sure how to integrate React and how to form arrays to sum the values (here "wert") later.



  Kategorie hinzufügen: add category

  Zahlenwert hinzufügen: add value

  dropdown: where you can choose categories

  wert: where you insert the spent value

  eingabeNum: insertedNum

  eingabeText: insertedText



function grab(event) 
if (event.which === 13)










share|improve this question





















  • 1





    Looks like you are using Jquery instead of react. And your question is not really clear to me. What do you mean by create new lis in an array? What is lis?

    – Hung Cao
    Mar 26 at 18:13











  • i think, it's all <li> elements.

    – Nina Scholz
    Mar 26 at 18:20













-2












-2








-2








My team is working on a web application to display personal finances.
We would like the user to add their spendings with the matching category (e.g. $50 for food) and make those entries lis. We then want to take the sum of, for example, all the food entries and display it. So we need to somehow get those lis in arrays - that's what I think. And somehow the new lis, which are not there yet, must have some special id (?) so they "find" each other (meaning, all food values go to the food array)? And is there a way to do it with React?



I'm not sure how to integrate React and how to form arrays to sum the values (here "wert") later.



  Kategorie hinzufügen: add category

  Zahlenwert hinzufügen: add value

  dropdown: where you can choose categories

  wert: where you insert the spent value

  eingabeNum: insertedNum

  eingabeText: insertedText



function grab(event) 
if (event.which === 13)










share|improve this question
















My team is working on a web application to display personal finances.
We would like the user to add their spendings with the matching category (e.g. $50 for food) and make those entries lis. We then want to take the sum of, for example, all the food entries and display it. So we need to somehow get those lis in arrays - that's what I think. And somehow the new lis, which are not there yet, must have some special id (?) so they "find" each other (meaning, all food values go to the food array)? And is there a way to do it with React?



I'm not sure how to integrate React and how to form arrays to sum the values (here "wert") later.



  Kategorie hinzufügen: add category

  Zahlenwert hinzufügen: add value

  dropdown: where you can choose categories

  wert: where you insert the spent value

  eingabeNum: insertedNum

  eingabeText: insertedText



function grab(event) 
if (event.which === 13)







javascript arrays reactjs sum






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 2:06









karel

2,4929 gold badges29 silver badges32 bronze badges




2,4929 gold badges29 silver badges32 bronze badges










asked Mar 26 at 17:59









JinLinoJinLino

1




1










  • 1





    Looks like you are using Jquery instead of react. And your question is not really clear to me. What do you mean by create new lis in an array? What is lis?

    – Hung Cao
    Mar 26 at 18:13











  • i think, it's all <li> elements.

    – Nina Scholz
    Mar 26 at 18:20












  • 1





    Looks like you are using Jquery instead of react. And your question is not really clear to me. What do you mean by create new lis in an array? What is lis?

    – Hung Cao
    Mar 26 at 18:13











  • i think, it's all <li> elements.

    – Nina Scholz
    Mar 26 at 18:20







1




1





Looks like you are using Jquery instead of react. And your question is not really clear to me. What do you mean by create new lis in an array? What is lis?

– Hung Cao
Mar 26 at 18:13





Looks like you are using Jquery instead of react. And your question is not really clear to me. What do you mean by create new lis in an array? What is lis?

– Hung Cao
Mar 26 at 18:13













i think, it's all <li> elements.

– Nina Scholz
Mar 26 at 18:20





i think, it's all <li> elements.

– Nina Scholz
Mar 26 at 18:20












1 Answer
1






active

oldest

votes


















0














It doesn't look like you're using React (you're appending new elements with jQuery). So if you're just working with DOM elements you could include a CSS class on each element <li class="food">..</li>. Then you could select them easily $("li.food").



You also need the value of the element. You could navigate from the li to the span that contains the value and get it from there, but it's getting pretty messy. Maybe it would be cleaner to include the item value as a HTML attribute:



$("ul").append("<li class='food' itemValue='" + eingabeNum + "'><span class='trash'><i class='fa fa- 
trash '></i></span> " + eingabeText + "<span
class = 'betrag' > " + eingabeNum + "€ < /span></li > ")


Then you could easily get it from the <li>.



let sum = 0;
$("li.food").each(function()
sum += $(this).attr("itemValue");
);
console.log("Sum of food items: " + sum);





share|improve this answer
























    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%2f55363557%2fcreate-a-new-lis-in-an-array-and-then-sum-their-values%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









    0














    It doesn't look like you're using React (you're appending new elements with jQuery). So if you're just working with DOM elements you could include a CSS class on each element <li class="food">..</li>. Then you could select them easily $("li.food").



    You also need the value of the element. You could navigate from the li to the span that contains the value and get it from there, but it's getting pretty messy. Maybe it would be cleaner to include the item value as a HTML attribute:



    $("ul").append("<li class='food' itemValue='" + eingabeNum + "'><span class='trash'><i class='fa fa- 
    trash '></i></span> " + eingabeText + "<span
    class = 'betrag' > " + eingabeNum + "€ < /span></li > ")


    Then you could easily get it from the <li>.



    let sum = 0;
    $("li.food").each(function()
    sum += $(this).attr("itemValue");
    );
    console.log("Sum of food items: " + sum);





    share|improve this answer





























      0














      It doesn't look like you're using React (you're appending new elements with jQuery). So if you're just working with DOM elements you could include a CSS class on each element <li class="food">..</li>. Then you could select them easily $("li.food").



      You also need the value of the element. You could navigate from the li to the span that contains the value and get it from there, but it's getting pretty messy. Maybe it would be cleaner to include the item value as a HTML attribute:



      $("ul").append("<li class='food' itemValue='" + eingabeNum + "'><span class='trash'><i class='fa fa- 
      trash '></i></span> " + eingabeText + "<span
      class = 'betrag' > " + eingabeNum + "€ < /span></li > ")


      Then you could easily get it from the <li>.



      let sum = 0;
      $("li.food").each(function()
      sum += $(this).attr("itemValue");
      );
      console.log("Sum of food items: " + sum);





      share|improve this answer



























        0












        0








        0







        It doesn't look like you're using React (you're appending new elements with jQuery). So if you're just working with DOM elements you could include a CSS class on each element <li class="food">..</li>. Then you could select them easily $("li.food").



        You also need the value of the element. You could navigate from the li to the span that contains the value and get it from there, but it's getting pretty messy. Maybe it would be cleaner to include the item value as a HTML attribute:



        $("ul").append("<li class='food' itemValue='" + eingabeNum + "'><span class='trash'><i class='fa fa- 
        trash '></i></span> " + eingabeText + "<span
        class = 'betrag' > " + eingabeNum + "€ < /span></li > ")


        Then you could easily get it from the <li>.



        let sum = 0;
        $("li.food").each(function()
        sum += $(this).attr("itemValue");
        );
        console.log("Sum of food items: " + sum);





        share|improve this answer













        It doesn't look like you're using React (you're appending new elements with jQuery). So if you're just working with DOM elements you could include a CSS class on each element <li class="food">..</li>. Then you could select them easily $("li.food").



        You also need the value of the element. You could navigate from the li to the span that contains the value and get it from there, but it's getting pretty messy. Maybe it would be cleaner to include the item value as a HTML attribute:



        $("ul").append("<li class='food' itemValue='" + eingabeNum + "'><span class='trash'><i class='fa fa- 
        trash '></i></span> " + eingabeText + "<span
        class = 'betrag' > " + eingabeNum + "€ < /span></li > ")


        Then you could easily get it from the <li>.



        let sum = 0;
        $("li.food").each(function()
        sum += $(this).attr("itemValue");
        );
        console.log("Sum of food items: " + sum);






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 27 at 5:06









        MattMatt

        2,7671 gold badge10 silver badges20 bronze badges




        2,7671 gold badge10 silver badges20 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            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%2f55363557%2fcreate-a-new-lis-in-an-array-and-then-sum-their-values%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

            How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

            해남서초등학교 학교 연혁 학교 동문 외부 링크 둘러보기 메뉴북위 34° 34′ 21″ 동경 126° 35′ 50″ / 북위 34.5726385° 동경 126.5972670°  / 34.5726385; 126.5972670해남서초등학교eh