Top 20 JavaScript array methods every JS beginner should know!!

A thread 🧵
Quick array method recap:

Array methods are built-in functions in JavaScript that you apply to arrays. Each method has a particular function that changes or manipulates the array.

It saves us time because we can use methods instead of hard coding everything!!😆
1️⃣ pop()

pop() removes the LAST element of an array and returns that removed element. This method changes the original array and its length.
2️⃣ push()

The opposite of pop(), push() adds one or more elements to the back of an array. This method changes the original array, and returns the length of the changed array.
3️⃣ shift()

shift() removes the FIRST element of an array, and returns the removed element. This method also changes the original array and its length.
4️⃣ unshift()

unshift() is the opposite of shift()! unshift() adds one or more elements to the start of an array, and returns the new length of the array.

Order matters; the elements will show up in the order in which you pass them in unshift().
5️⃣ slice()

slice() selects a chunk of an array & returns a NEW array with a copy of all elements selected from the start index to the end index. The original array does NOT change.

The element with the ending index isn't included.
6️⃣ splice()

splice() DOES change the original array. It removes, replaces, or adds new elements to the array.

splice() method returns an array of the deleted elements. If 0 elements are removed, it returns an empty array.
7️⃣ join()

join() returns a NEW STRING of array elements either separated by commas or a specified separator.

If there’s only one element in the array, that element is returned as a string with no separator.
8️⃣ toString()

toString() converts an array into a string.
9️⃣ forEach()

forEach() helps you loop through the elements of an array. For every array element, it executes a callback function.
🔟 filter()

filter() returns a NEW array that 'filters' out elements from an array.

Each element of the array is passed to a callback function that either returns `true` or `false`. If the callback returns `true` for a specific element, that element is added to the new array.
1️⃣1️⃣ includes()

includes() checks if the array includes the item passed to the method. It returns either `true` or `false`.
1️⃣2️⃣ map()

map() creates a NEW array with the return value of the callback function called on each element in the array.
1️⃣3️⃣ Array.from()

Array.from() creates a NEW real array from an array-like/iterable object. This is useful when you're working with DOM, or when you want to use array methods, such as, map(), filter(), etc.
1️⃣4️⃣ concat()

concat() merges two or more arrays into a NEW array.
1️⃣5️⃣ reverse()

reverse() reverses an array; the first element becomes last, and the last becomes first. It changes the original array, and it returns the reversed array.
1️⃣6️⃣ sort()

sort() sorts the elements of an array in ascending order. This means is that it first converts the elements into strings, then compares its code (UTF-16). It changes the original array, and returns the sorted array.
1️⃣7️⃣ every()

every() tests if every element in an array passes the test implemented by the callback function. It returns a boolean value.

If all elements in the array return `true` when passed the function, every() returns `true`.
1️⃣8️⃣ some()

Similar to every(), some() returns `true` if ANY (some) element in the array passes the test implemented by the callback function.

Every element isn't required to pass the callback; if one element returns `true`, some() method returns `true`
1️⃣9️⃣ reduce()

reduce() reduces the array into a single element. It passes the return value of the previous element in the callback function.

To put it simply, it kind of adds the result of the previous value to the current value.
2️⃣0️⃣ findIndex()

findIndex() returns the index of the first element in the array that satisfies the callback function. If no elements pass the test provided by the callback function, findIndex() returns -1.
We've finally come an end to this thread, I know you probably feel dead AF LOL😂

Thank you for making it this far, and hopefully this thread helps you to remember or have a refresh of JS array methods!!

If you liked this thread, check me out @codingyuri !!

• • •

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

Keep Current with Yuri 🇰🇷

Yuri 🇰🇷 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 @codingyuri

16 Sep
7 FREE resources/courses to learn web development!!

A thread 🧵
1️⃣ The Odin Project

I love the Odin Project!!💛
It's how I started my web dev journey. It's THE BEST full stack curriulum I've seen so far. I really like TOP because it doesn't hold your hand; it forces you to solve problems by yourself!!

theodinproject.com
2️⃣ Full Stack Open

This course is for the intermediate, definitely for people who are familiar with the basics!! You don't gotta be an expert, you just gotta be familiar with vanilla JavaScript and the DOM.

fullstackopen.com/en/
Read 9 tweets
12 Sep
I got 25K & a job at Hashnode within 2 months in Tech Twitter!

A thread on building an audience 🧵
Building an online presence puts you out there!

It shows your personality, what you're passionate about, & what you're working on. Depending on how you use it, it can be very beneficial!!
Being self-taught, building an audience opened many doors, and gave me opportunities I never dreamed of!

Joining Tech Twitter has been one of the best decisions I've made, & I'm forever grateful at the community ❤️

It can be an amazing experience, so make the most out of it!
Read 16 tweets
22 Aug
Continuing my Frontend thread...this is the BACKEND ver!🔥

A list of the top Udemy courses for each slide of Brad Traversy's 2021 Web Development roadmap😆

This thread is for aspiring backend developers!

Includes: node.js, python, backend frameworks, database, etc.

A thread🧵
👉 Backend Languages

💚NodeJS

1⃣ The Complete Node.js Developer Course - Andrew Mead (35hrs)

2⃣ Learn & Understand NodeJS - Anthony Alicea (13hrs)

3⃣ NodeJS - The Complete Guide - Max Schwarzmüller (40.5hrs)
4⃣ Node.js, Express, MongoDB & More: The Complete Bootcamp 2021 - Jonas Schmedtmann (42hrs)

5⃣ Node JS: Advanced Concepts - Stephen Grider (16hrs)

6⃣ Node.js API Masterclass With Express & MongoDB - Brad Traversy (12hrs)
Read 21 tweets
21 Aug
I love Udemy !!❤️

So, I made a list of the top Udemy courses for each slide of Brad Traversy's 2021 Web Development roadmap😆

This thread is for aspiring frontend developers!

Includes: HTML/CSS, JavaScript, Frontend frameworks, TypeScript, etc.

A thread🧵
👉 HTML/CSS

1⃣ Build Responsive Real-World Websites with HTML and CSS - Jonas Schmedtmann (49.5 hrs)

2⃣ Web Design for Beginners: Real World Coding in HTML & CSS - Brad Schiff (11 hrs)

3⃣ Modern HTML & CSS From The Beginning - Brad Traversy (21 hrs)
CSS & SASS

1⃣ Advanced CSS and Sass: Flexbox, Grid, Animations and More! - Jonas Schmedtmann (28 hrs)

2⃣ CSS - The Complete Guide 2021 (incl. Flexbox, Grid & Sass) - Maximilian Schwarzmüller (22.5 hrs)
Read 20 tweets
12 Aug
10 most common Mac Terminal commands (in my experience)

A thread 🧵
1⃣ pwd

Use the `pwd` command to find out your current location in the filesystem/name of the folder currently open in your terminal window.

After executing `pwd` command, terminal tells us that we're in `Yuri` directory inside of `Users` at root
2⃣ ls

The `ls` command is used to list all the folders/files under the location specified, or if not specified, under the current location.

Here, we're listing all the directories/files inside `~`
Read 15 tweets
11 Aug
⭐️Tech Trivia Tues⭐️

ANSWER: '55'

This is because of how type conversion and the .join() method work on JavaScript.

I'll walk you through the code on the thread below 👇🧵
Type conversion in JavaScript can be a little bit weird.

If do math with a number and a non-numeric value, JS will try to convert the non-numeric value into a number.

In this case, when `true` is converted to a number value, it returns the number 1.
Check out the code below:

The following expression will return 5 because 1 * 5
Read 6 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!

:(