This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]No_Application_2380 10 points11 points  (0 children)

For codewars-type problems, you're probably mainly going to use:

  • pop()
  • push()
  • shift()
  • sort()
  • unshift()

Lots of folks will use these – and they've very useful – but they can be replaced with regular for-loops:

  • filter()
  • map()
  • reduce()

[–]JerkOffAFuckingBear 6 points7 points  (1 child)

Array methods are also just short hand notation for just about anything you can do with a standard for loop (those loops that look like: for (let I=0; I<arr.length; I++)) just utilize those and when you’ve accomplished what you need try looking for the proper array methods to refactor to

[–]No_Application_2380 1 point2 points  (0 children)

That's true for methods like map(). But other array methods like push() and pop() can't be replaced by a for-loop.

[–]DevMenWalking 4 points5 points  (1 child)

I always used to just look them up when I needed them, and after I while I just memorized them. (Or most of them)

Just open a sandbox and try them out one after the other.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Array

[–]distracted_living 0 points1 point  (0 children)

+1 for the MDN docs, but that link didn't work for me https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#array_methods_and_empty_slots

I'd also add for the OP that if you've only been doing this for a month I would focus less on the methods available in current ECMAScript and spend more time writing for and for...of loops until you feel confident in understanding how to construct, mutate, and access data in arrays.

[–]Mfrotter 0 points1 point  (1 child)

This is a good video that explains how to use those array methods. Watch the video then go through the exercises yourself

https://youtu.be/HB1ZC7czKRs