0
Array with for loop in javascript
How to iterate throw an array of number in js? Given array of number values called prices var prices= [40,56,67,87,90]; An amount number will be given as user input or a static variable var amount = 12; How to added this amount to each element in the array? Using a for loop with the array.length method as test condition: for(var i= 0;i<prices.length;i++){ //Here goes your code to increase each prices element prices[i] += amount; }
8 Respostas
+ 6
Hi there.. I really appreciate that you wanted to teach others what you've learnt. That's great.... Keep teaching others...
đđđâșâșâșđđđ
But, this is a wrong place to teach others. This section is for asking questions and other users will try to answer it and help.
đđđđ
You can post your lesson in your posts section in your profile.đđ
-> Profile
-> Goto Posts
-> Create new post by clicking on bottom-right plus icon
-> write your lesson
-> post it
+ 5
Is this a tutorial for others instead of a question?
+ 5
Actually U have answered the Question yourself ...
The loop you have written in the description is the code to iterate through an array of numbers in Js .
+ 2
I prefer to use predicate functions to perform any sort of recursive mathematical transformation on a data structure.
My solution uses arrow functions.
const newPrices = prices.map(n => n+amount);
+ 2
No Steve Sajeev I don't have this intention to teach other but I want just to finish my courses in jscript so it is a way to understand more those topics
+ 2
But still, please do not post this here. This is not the right place. Please understand..đ
+ 1
1. Your variant
2. for(let k of prices){k+=amount} Here k is element of array itself
3. prices= prices.map(val=>val+amount);
+ 1
HBhZ_C Did you say "JScript" as in JScript, Microsoft's old JavaScript engine. I don't consider it a good choice if you are new to JavaScript. I advise that you first learn standard EcmaScript(ES 2020) before trying out any other implementation.