Most important methods of your JavaScript codebase.
In day-to-day development with JavaScript in the form of frontend framework or backe...
For further actions, you may consider blocking this person and/or reporting abuse
Your
map
example is poor as it is modifying the content of the original array... something thatmap
is designed to help you avoid. It may confuse people into believing the the original array is always modified.Check out the new modifications. Thanks
No, it might looks like muteble but but will change it. Thankyou
Believe me, it definitely will. Run the code, then check the original array. I guarantee it will have changed.
To do what your example's introduction describes, you need to do something like this - which will leave the original array untouched:
Or if you prefer something closer to your original:
In your example, the newly created array contains the same objects as the original array, and you have modified those. To leave the original array untouched, you need to make copies of the student objects and work on those.
Hi Milan, In addition to Jon's comment, the second point you made is not quite correct. Instead of "Return the array with the same number of elements present.", it would be more accurate to state "Returns a new array with the same number of elements as the original." but this is not being demonstrated by your example.
To confirm this, you could check what is returned by the
map
operation against the original array (after performing the operation).Sorry to be picky but I also think you mean "transform" rather than "transfer" in your points about
map
.Thanks for commenting, love to unlearn and learn the correct way.
check out the new modifications. thanks
Hi Milan, The example is far more representative of a typical use case. I still think the first two bullet points are not quite right and the following might be better:
The
reduce
example needs a little work and should present the return value.Please accept my comments in the spirit of friendship and knowledge sharing.
I think its fine if content like this already exists on dev.to already, from my perspective dev.to is more about opening discussions on some topics and also for people to offer feedback to content creators and also help them improve, so this is a good start!
Thanks @dsaga
Agree!
Array methods are essentials.
Agree too.
Hi!
Array methods FTW!
You can shorten your code a tad more:
becomes (notice strict comparison as well)
Your
reduce
example becomes:Also, under
entries
you wrote :What do you mean by
converted to an object
? Are you referring toObject.fromEntries
which creates an object from an array of entries?And lastly, it'd be more interesting if you showed what
students
variable holds. It would allow "noobs", to quote you, to play with the code at home.Full doc on arrays.
Thanks for commenting. I wrote this to make a type of notes of what I studied. I will consider your thoughts on my upcoming notes. check out the correction I made on
entries()
. Thanks for your time.Just saw your edit, almost there!
entries
does not return an object iterator but an array.Also:
You probably mean
concatenate
.It returns the result of concatenating two arrays.
I'm not being picky, using the right vocabulary helps understanding concepts.
Yes agreed, thanks @joolsmcfly
It returns iterator in case of Array.
Also concat can be replaced with spread operator:
a.concat(b) is the same as [β¦a, β¦b]
yaa right, thanks
JSON.stingify()
&JSON.stingify()
??I think the author meant
JSON.stringify
andJSON.parse
(correct me if I'm wrong)yes thanks.
yaa, I forgot. Thank you for reminding me.
Good!
Thanks Henry
I think people need to stop posting the same stuff with different titles. There are way too many articles about arrays and how they work.
Thanks, @softmantk for your time, I write this as my notes. Whatever I am studying I am trying to make notes like articles.
I feel like the MDN documentation does a better job of explaining these, and does so without the unkind clickbait title.
Thank you for your time, I will try my best in my upcoming notes.
*JSON.stringify()
super
Thanks @mythilisundarajan