JavaScript 💡

14 Array Methods that will make your life easier.
Explanation and examples below.

🧵👇
🔸 map

The map() method creates a new array populated with the return value of the callback function for each element in the array.
🔸 forEach

The forEach() method executes a provided function once for each array element.
The callback function does not expect a return value, and the forEach() method itself also returns undefined.
🔸 filter

The filter() method creates a new array containing only the elements that "pass the test" implemented by the callback function.
We call this type of callback a predicate function.
🔸 find

The find() method behaves similarly to the filter() method, but it only returns a single element.
This method will stop at the first element that "pass the test", and return that.
If none exists, it will return undefined.
🔸 findIndex

The findIndex() method behaves similarly to the find() method, but it returns an index instead of the element,
This method will stop at the first element that "pass the test", and return its index.
If none exists, it will return -1.
🔸 reduce

The reduce() method takes a callback with (at least) two arguments:
An accumulator and the current element.

For each iteration, the return value of the callback function is passed on as the accumulator argument of the next iteration.
🔸 some

The some() method takes a predicate function and return true if any of the elements in the array "passes the test".
🔸 every

The every() method takes a predicate function and returns true if all of the elements in the array "pass the test".
🔸 includes

The includes() method checks if an array includes a certain value among its elements, returning true or false.
🔸 fill

The fill() method replaces all the elements in an array to a given value.
🔸 reverse

The reverse() method reverses the order of the elements in the array.
🔸 flat

The flat() method creates a new array with all sub-array elements flattened into it.
You can specify a depth. The default is 1.
🔸 flatMap

The flatMap() method applies a callback to each element of the array and then flatten the result into an array. It combines flat() and map() in one function.
🔸 sort

The sort() method is used to sort the elements of an array and returning the sorting array.
Be aware that this method is mutating the original array.
If you want to learn more about JavaScript Array Methods, be sure to watch this YouTube video.

I reimplement forEach, map, filter, and reduce.

This often comes up in job interviews - acing this challenge will give you some serious points 🔥

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Simon Høiberg

Simon Høiberg Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @SimonHoiberg

8 Apr
8 JavaScript Concepts you need to be familiar with!

🔸 Scopes
🔸 Closures
🔸 Reference/Pointers
🔸 This
🔸 Prototypes & Inheritance
🔸 Async/Await (Promises)
🔸 Higher-order Functions
🔸 Event Propagation

🧵👇
Read 10 tweets
6 Apr
🔥 5 Awesome Design Tools 🔥

Have you been eyeing these cool cards and thumbnails that a lot of us are sharing?

Do you want to get started as well?
Here are 5 tools to get you going 👇 🧵
🔸 Figma

This is the one I personally prefer.
It's a little more advanced than other tools, but you can really make some cool stuff once you get familiar with it.

figma.com
🔸 Canva

This is a super popular tool - if you're a beginner in graphic design, this tool is for you!

canva.com
Read 6 tweets
4 Apr
"Stop having expectations".
It's advice I hear really often - and I don't buy it at all!

Have loads of expectations 🤩
It can be pure joy if you let it!
First of all, you can't really cheat your brain.
It'll have expectations - that's pretty much what the brain does; makes predictions.

Have you ever tried to "talk yourself down" in fear of getting disappointed, and when it then happened - you got disappointed anyway 😅
That's because you can't fool yourself.
If you know that there's a chance of something really good happening (even if the odds are low), there will be some expectation.

Embrace it instead 😍
Isn't it the best feeling in the world, hoping that something really cool might happen?
Read 5 tweets
26 Mar
How profitable is FeedHive at this very moment? 🤩

Let's break it down.
The answer may be surprising 🧵 👇
Let's do a snapshot at this very point in time, and take a look at how profitable FeedHive is!

In total, FeedHive has made:
$3,650
That's great.
But let's take a look at some of the expenses.

We got @dan_spratling involved, and he's currently building a new marketing website.

It's really cool 🔥
But we also had to pay him for his hard work.

-$3,500.
Read 12 tweets
25 Mar
10 Awesome Developer Tools ⭐️
Start using these in 2021.

🔸 Visual Studio Code
🔸 Postman
🔸 Oh My Zsh
🔸 GitHub CLI
🔸 GitHub Desktop
🔸 GitHub Actions
🔸 Slack
🔸 Cypress
🔸 Codepen
🔸 CodeSandbox
🔸 Visual Studio Code
code.visualstudio.com
🔸 Postman
postman.com
Read 11 tweets
25 Mar
5 annoying JavaScript habits that you want to avoid.

I see these 5 over and over.

They are bad for performance, readability, and they signal a lack of basic understanding of the JavaScript language.

Let me go through them here 🧵👇
Using map() instead of forEach().

Arrays expose different methods for different purposes.
If you are simply iterating through a list, you want to use forEach(), not map().

Using the wrong method may miscommunicate the intent.
Creating an extra arrow function (thus an extra function closure), while not being necessary is both bad for readability and bad for performance.

It's a sign that the author doesn't truly understand that in the nature of JavaScript, you can pass functions by reference.
Read 7 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!