Variables in Javascript allow only one data to be stored at a time. However, given that it is often useful to manipulate many data, the concept of ...
For further actions, you may consider blocking this person and/or reporting abuse
so... I also want to jump on the complaints wagon for a moment here: why is everything emphasized!? grr... this just makes the paragraphs unnecessarily difficult to read.
but yeah, two issues I spot here:
length
is most definitely a property, not a method..[1, 2, 3, 4, 5].join("-")
does not result in[1-2-3-4-5]
.. this results in the string"1-2-3-4-5"
.lastly, why are you showing the final result of calling these functions as though they were assignments? that in itself is also confusing AF.. so much so, that it might actually mislead anyone who is still learning the cute and cuddly monster that is JavaScript.
...and you forgot to mention the spaces added to various string elements of the altered array 😅
I like how shift() adds a space to all other elements 😅
array.length() is a function? or is it a mistake?
It's a property (array.length) if I remember right.
length is a property of arrays in JavaScript i think it is mistake
This information is good. Thanks for taking the time to gather this. I know there are few comments on the errors coming your way but don't let that stop you from writing. Let them help you write better..Waiting for your next article.
Serialize from low value to high value using Array.sort
const a = [1, 6, 3]
const result = a.sort((a, b) => a - b)
console.log(result) // [1, 3, 6]
The definitive Array guide. My favourite part is the length... method? XD
Thank you for taking the time in trying to create a useful article for every JavaScript developer to use.
There are a few mistakes in your screenshots starting with the first .length screenshot. I'm not trying to point out what others already commented about it not being a method, but at the answer 4. What I would suggest is to sometimes test your code, this can be as simple as just opening your inspect tool (press F12 or right click in your browser and then select inspect), and go open the console tab. I alway find this a very useful thing to do, if I want to test code. There are loads of tools to test code but I find my browser console the easiest and for some unexplained reason "the cleanest" (probably just personal preference). I'd like to ask you to look at all of your screenshots and test them. I am only pointing out this one because it's the first one people will notice.
Hopefully you continue to write articles, make mistakes, learn and improve. It's truly one of the best ways to get better as a developer! Looking forward to your next post!
Yes definetly, with mistake I'll learn a lot, and comment from other people help me a lot... Thanks community, Thanks Andy 🙏🏿
This tool by Sara Drasner is interesting and helpful: sdras.github.io/array-explorer/
Even pro developers need to refer to the documentation on arrays every once in a while 😅
A nice one - thank you!
confusion with filter & map
@shamol
Assuming that an array has n elements, the filter function can return 0 to n elements, based on the condition. Such as
const even = [1,2,3,4,5,6].filter(n => n %2 === 0); // returns [2, 4, 6];
Assuming that an array has n elements, the map function will run every array element through the function and return n elements.
const double = [1,2,3,4,5].map(n => n * 2); // returns [2, 4, 6, 8, 10];
Hope this clears.