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;
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
add a comment |
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
1
Looks like you are using Jquery instead of react. And your question is not really clear to me. What do you mean bycreate new lis in an array? What islis?
– Hung Cao
Mar 26 at 18:13
i think, it's all<li>elements.
– Nina Scholz
Mar 26 at 18:20
add a comment |
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
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
javascript arrays reactjs sum
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 bycreate new lis in an array? What islis?
– Hung Cao
Mar 26 at 18:13
i think, it's all<li>elements.
– Nina Scholz
Mar 26 at 18:20
add a comment |
1
Looks like you are using Jquery instead of react. And your question is not really clear to me. What do you mean bycreate new lis in an array? What islis?
– 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
add a comment |
1 Answer
1
active
oldest
votes
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);
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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);
add a comment |
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);
add a comment |
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);
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);
answered Mar 27 at 5:06
MattMatt
2,7671 gold badge10 silver badges20 bronze badges
2,7671 gold badge10 silver badges20 bronze badges
add a comment |
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 islis?– Hung Cao
Mar 26 at 18:13
i think, it's all
<li>elements.– Nina Scholz
Mar 26 at 18:20