Тёмный

20+ Must Know Array Methods That Almost Nobody Knows 

Web Dev Simplified
Подписаться 1,6 млн
Просмотров 89 тыс.
50% 1

Опубликовано:

 

27 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 155   
@FunctionGermany
@FunctionGermany 9 месяцев назад
flatMap is NOT like .flat() .map(), it's like .map() .flat(), very different!!
@WebDevSimplified
@WebDevSimplified 9 месяцев назад
Good point. I messed up when talking about this.
@ehm-wg8pd
@ehm-wg8pd 9 месяцев назад
they should call it matFlap
@xiaozhenxiang
@xiaozhenxiang 9 месяцев назад
​@@ehm-wg8pdflatMap = flat the map
@JokeryEU
@JokeryEU 9 месяцев назад
also flatMap only goes 1 lvl deep
@VladBurlutsky
@VladBurlutsky 9 месяцев назад
Always read the ECMAScript specs, that's what all hardcore JS programmers use! The Array.prototype.flatMap and Array.prototype.flat methods in JavaScript are quite similar in their functionality, but they have some key differences: Functionality: flatMap: This method first maps each element using a mapping function, then flattens the result into a new array. It's essentially a combination of the map and flat methods. flat: This method simply flattens an array up to a specified depth and does not perform any mapping. Mapping Function (mapperFunction): flatMap: Requires a mapperFunction as its first argument. This function is called on every element of the array, and the results are then flattened. flat: Does not take a mapping function. It only flattens the array based on the specified depth. Depth Specification: flatMap: Implicitly flattens the array only one level deep. It does not accept a depth argument. flat: Accepts an optional depth argument that determines the depth level to which the array should be flattened. If depth is not provided, the default is one level deep. Error Handling (TypeError): flatMap: Throws a TypeError if the provided mapperFunction is not callable. flat: There's no such error condition specifically related to the function's argument since it doesn't require a function as an argument. Depth Handling in flat: flat: Contains additional steps to handle the depth parameter. If depth is undefined, it is treated as 1, and if it is less than 0 after conversion to an integer, it is set to 0.@@WebDevSimplified
@akbhere-o8x
@akbhere-o8x 9 месяцев назад
Group by & differences were totally new to me. Thanks for the video mate
@DarrenJohn10X
@DarrenJohn10X 9 месяцев назад
.at() got all the excited press, meanwhile .with() was virtually ignored. Thanks Kyle for talking about both together.
@sarveshdhiman15
@sarveshdhiman15 7 месяцев назад
In a single video I learn lot of things with proper explanation and with so ease. Thanks 🙏
@quanghungpham269
@quanghungpham269 9 месяцев назад
I used most of these method quite frequently, they are super useful. My fav one is reduce(), it's very useful when you want to reduce the array to a value and then use that value, also I got headache many times from using it :)
@magnanova
@magnanova 9 месяцев назад
It's about time they added those Set difference/intersection methods!
@harmez7
@harmez7 9 месяцев назад
Kyle, thank you for speaking so clearly. Im not that good at English but I can completely understand you, that's why I subbed to here years ago.
@rdubb77
@rdubb77 7 месяцев назад
It’s true, his pacing and diction is very good.
@roebucksruin
@roebucksruin 9 месяцев назад
An important distinction of .fill(), it fills the array with a static value. If you’re filling with an object, it’s the exact same object in memory. I tried to use it with the array constructor to convert an integer into an array of objects with a length of said integer, and every index would change on edit.
@davidj6755
@davidj6755 9 месяцев назад
I’m excited about the set theory operators. I hope that eventually gets full support across major browsers.
@tropicaljupiter
@tropicaljupiter 9 месяцев назад
Every day we stray further from lodash’s light
@ryan.wakefield
@ryan.wakefield 9 месяцев назад
The one thing I felt like was missing from this video is that you usually make sure to provide example situations in when you might use the code, and more importantly why. Otherwise, learned a lot of cool new stuff I will try to find a use for. Thanks!
@GuildOfCalamity
@GuildOfCalamity 9 месяцев назад
Kyle's hair should have its own channel.
@ukaszzbrozek6470
@ukaszzbrozek6470 9 месяцев назад
I know them all except the set methods. Thanks for a great reminder. When using shift and unshift we should remember that is a very non-performant action because the array need to recalculate all indexes. We should avoid using them. To be honest knowing about at method didn’t change that I am still using array[array.length - 1] syntax. It is such strong muscle memory that I write that without thinking. XD
@ryanlinnane
@ryanlinnane 9 месяцев назад
The shift methods are good for interviews for quickly representing a deck.
@NiceChange
@NiceChange 8 месяцев назад
Great video. Kyle makes JS fun and interesting...not an easy thing to do. 😊
@rajasMusicalJourney
@rajasMusicalJourney 2 месяца назад
Thanks Kyle the video is very informative
@MuhammadAitisamYaseen
@MuhammadAitisamYaseen 9 месяцев назад
Bro you really helped a lot. Thank you!
@kuhaniresti
@kuhaniresti 9 месяцев назад
hey, did it come into your mind of building hair gel products lately? great tutorials always
@ahmadfahim6467
@ahmadfahim6467 9 месяцев назад
Thanks man, especially the flapmap and explaining array mutations
@felixkiptoo421
@felixkiptoo421 9 месяцев назад
You really did simplified my flatMap() understanding
@yellowbonbon1
@yellowbonbon1 8 месяцев назад
Thank you for this sharing very helpful. Just want to add this, toReversed, toSorted and toSpliced create a new array. However, they do not do deep clone. In some use case, React could not detect the change if the change is within an object of object. It will be better to note this. "create a new array" somehow could cause confusion.
@jischkebd
@jischkebd 9 месяцев назад
you explain these concepts better than the majority of the teachers out there!
@sureshanandsekar4384
@sureshanandsekar4384 9 месяцев назад
sir could you please tell me where is the link for that cheet sheet , am ur new subscriber . you are my guru. and getting each time inspired by ur video ....
@0luckyluca0
@0luckyluca0 9 месяцев назад
amazing timestaps, i always wanted to skip to the topic "6" :D
@BokoMoko65
@BokoMoko65 9 месяцев назад
Curiously, it's note supported in Node.js. Although it's very easy to implement function groupBy(list, keyGetter) { return list.reduce((ac, curr) => { const key = keyGetter(curr); ac[key] = ac[key] || []; ac[key].push(curr); return ac; }, {}); }
@michaelharrington5860
@michaelharrington5860 9 месяцев назад
Alternative: function groupBy(array, key) { return array.reduce((groupedItems, item) => { const keyValue = item[key]; if (!groupedItems[keyValue]) { groupedItems[keyValue] = []; } groupedItems[keyValue].push(item); return groupedItems; }, {}); } let groupedByName = groupBy(people, 'name'); console.log(groupedByName);
@Thassalocracy
@Thassalocracy 9 месяцев назад
It's unfortunate that a lot of these methods are not used more due to the predominance of React in the JavaScript world. React wants to go the way of purely functional programming, so mutating functions like pop, shift, unshift are a big no-no. But if somehow JavaScript could be used in data science then these methods could really come in handy. But first, someone has to come up with handy data science packages like numpy, pandas, scikit 😅 PS: I actually did post a comment earlier but deleted it because I made some mistakes and didn't want to create unneeded controversy 😅
@daleryanaldover6545
@daleryanaldover6545 9 месяцев назад
good thing we don't use react in our projects
@Shubham-h1z
@Shubham-h1z 9 месяцев назад
@@daleryanaldover6545 What is used?
@sethwright2518
@sethwright2518 9 месяцев назад
These new functions (most of them at least) are actually good for React specifically because they don't mutate the originals arrays.. so it works better for functional programming 🎉
@dave6012
@dave6012 9 месяцев назад
Shift and unshift are how I do BFS when writing algos in JS
@MichaelCampbell01
@MichaelCampbell01 9 месяцев назад
A fun exercise is to implement all these methods in terms of `reduce()`.
@aundefined
@aundefined 9 месяцев назад
Great video! Keep it up 💯
@vichikes
@vichikes 9 месяцев назад
Groupby is super useful
@BokoMoko65
@BokoMoko65 9 месяцев назад
the with method is kind of superfluous because we can already use the destructuring technique. Like, putting something at the beginning let inTheBeginning = [ newThing, ... people] let inTheEnd = [ ... people, newThing] But if the idea is to insert some value somewhere in the middle of the array, the with is handy indeed
@cadekachelmeier7251
@cadekachelmeier7251 9 месяцев назад
I use .fill when I just want to map over a range of numbers. Mapping over new Array(x) doesn't work since there aren't any keys. But you can do new Array(x).fill(0).map((val, index) => index)
@whosdr
@whosdr 9 месяцев назад
Array.from({length:x}) or [...Array(x)] are also viable solutions.
@raygan3
@raygan3 9 месяцев назад
Will it be automatically polyfilles if used eq in react?
@nidhijha7081
@nidhijha7081 9 месяцев назад
Only if i would have watched this video one day before, my interview could have been much better 😢
@codeguy11
@codeguy11 9 месяцев назад
"20+ Must Know Array Methods That Almost Nobody Knows": 💀 Me using VSCode's autocomplete (and sometimes MDN docs) to browse and explore all JavaScript APIs and features: *Look what they need to mimic a fraction of our power*
@ahmed37551
@ahmed37551 9 месяцев назад
i think you have done enough intros kyle. just keep in the bio.
@stanmarsh9458
@stanmarsh9458 9 месяцев назад
groupBy is top!
@andrillaf
@andrillaf 9 месяцев назад
It’s good to be a developer on Mac😎
@prafullkumar6369
@prafullkumar6369 9 месяцев назад
amazon-chime-sdk-component-library-react Please create a video on this
@aliampichelmilan3345
@aliampichelmilan3345 9 месяцев назад
Nice vidio crack!, greetings!
@Meat-t7z
@Meat-t7z 9 месяцев назад
Hi everyone, i have node js version 21, but i cant use this methods in vscode. How can i enable this methods?
@VisualArtRonny
@VisualArtRonny 8 месяцев назад
Apparently my face is buried inside MDN docs, since I knew all of them including the last Set methods
@BokoMoko65
@BokoMoko65 9 месяцев назад
Is there a method to "flat" an object? That is, to make a deep copy of the entire object made of other objects?
@benas989989
@benas989989 9 месяцев назад
Old way: const copy = JSON.parse(JSON.stringify(foo)) New way: const copy = structuredClone(foo)
@DarrenJohn10X
@DarrenJohn10X 9 месяцев назад
.fill() ignores in sparse arrays... just so folks are aware! So you can't build an array of 5 "*" with this: let a = Array(5).fill("*") You would need to first map to a non-undefined value every element you want star-ified.
@SamuelKarani
@SamuelKarani 9 месяцев назад
I think you made an error equating flatMap with flat(infinity).map. I agree with @FunctionGermany in the comments
@mecozir
@mecozir 9 месяцев назад
part yield function set key specify task
@cm3462
@cm3462 9 месяцев назад
Fantastic
@Pareshbpatel
@Pareshbpatel 9 месяцев назад
Nice one, Kyle. Thanks. {2023-12-14}
@LetrixAR
@LetrixAR 9 месяцев назад
The namings for some of these methods are really confusing
@21Kikoshi
@21Kikoshi 9 месяцев назад
As a youtuber i wonder if youtubers ever watch themselves at x2 or with no sound to see what its like
@amuuuinjured
@amuuuinjured 9 месяцев назад
knew all of them except last experimental methods...
@michaelharrington5860
@michaelharrington5860 9 месяцев назад
`groupBy` alternative for node.js users: function groupBy(array, key) { return array.reduce((groupedItems, item) => { const keyValue = item[key]; if (!groupedItems[keyValue]) { groupedItems[keyValue] = []; } groupedItems[keyValue].push(item); return groupedItems; }, {}); } let groupedByName = groupBy(people, 'name'); console.log(groupedByName);
@cristianjuarez1086
@cristianjuarez1086 8 месяцев назад
that is not an alternative
@turolretar
@turolretar 9 месяцев назад
“Let’s see Paul Allen’s array methods”
@BauldyBoys
@BauldyBoys 9 месяцев назад
CSS starts calling everything start and end Javascript starts using left and right. Classic.
@chrisjohanesen
@chrisjohanesen 9 месяцев назад
And then there’s “findLast” 🙄
@vaishnomatabhaktamandali2000
@vaishnomatabhaktamandali2000 9 месяцев назад
In bathroom rn but listening to lectures
@АртемЗеленов-л1р
@АртемЗеленов-л1р 9 месяцев назад
Is there a new way to get the last item in the array instead of the old array[array.length - 1]?
@Popo-pd3ps
@Popo-pd3ps 9 месяцев назад
Just simply use array.at(-1)
@foxcryptoboss
@foxcryptoboss 9 месяцев назад
something is very off with the camera and sound sync. looks scary.
@mecozir
@mecozir 9 месяцев назад
wait general fixed job dom
@olegkravchenko9655
@olegkravchenko9655 9 месяцев назад
С*ка, до слёз! Даже плюсик поставил от нахлыва чуйств :D
@LawJolla
@LawJolla 9 месяцев назад
This video taught me that someone still uses a PC. Wild.
@elpolodiablo5486
@elpolodiablo5486 9 месяцев назад
Are you a caveman ?
@genyklemberg
@genyklemberg 9 месяцев назад
Who cares what you are talking about, I already heard about it and still don't use it 😢 I think I need to visit coding interviews to practice that more often😂
@Anonymous____________A721
@Anonymous____________A721 9 месяцев назад
388th view
@CoryTheSimmons
@CoryTheSimmons 9 месяцев назад
reduce is king. Everything else is just a lodash helper.
@bryson2662
@bryson2662 9 месяцев назад
Most shocking referral, Kyle uses windows
@AGSTRANGERTunisianAuthor
@AGSTRANGERTunisianAuthor 9 месяцев назад
If almost nobody knows them then probably you don't need to know them
@yadusolparterre
@yadusolparterre 9 месяцев назад
How else am I going to flex in front of my colleagues
@vodafoneuser1690
@vodafoneuser1690 9 месяцев назад
As demonstrated in this video lol
@angrytvrobot6130
@angrytvrobot6130 9 месяцев назад
I'm sure there will be a few people who see this and go, "oh that will make my bit of code much easier!" There's probably a use case, or they wouldn't exist.
@TaufeeqAhmed-fq9hq
@TaufeeqAhmed-fq9hq 9 месяцев назад
Nice motto 👏👏
@VskiDevs
@VskiDevs 9 месяцев назад
He said they’re just as useful 🫴🏿
@mecozir
@mecozir 9 месяцев назад
post none if code expire
@piyushaggarwal5207
@piyushaggarwal5207 9 месяцев назад
Personal Notes, don't see - Object.groupBy(), Map.groupBy(), Array.with(1, 2), Array.at(-1), Array.fill(1, 1, 3), Array.toReversed(), Array.toSorted(), Array.toSpliced(), Array.flat(2), Array.findLast(), Array.reduceRight()
@SoreBrain
@SoreBrain 9 месяцев назад
Saved me some time, ty
@piyushaggarwal5207
@piyushaggarwal5207 9 месяцев назад
@@SoreBrain I have written down according to me. Skipping things.
@SoreBrain
@SoreBrain 9 месяцев назад
@@piyushaggarwal5207 I realized you left some out, coincidentally the ones I also don't care about (yet) or already knew well. Thanks for the edit and letting me know tho!
@mecozir
@mecozir 9 месяцев назад
wait general fixed job dom
@industrydzina
@industrydzina 9 месяцев назад
Important to note that the .fill method behaves differently when you fill the array with objects(including arrays), where it actually fills the array with a REFERENCE to the original object, so that if you perform a mutation on any of the objects in this array, it will perform the same mutation on all the elements in the array. Was stumped by this until ChatGPT helped point me to the docs on MDN...
@Ebiko
@Ebiko 9 месяцев назад
That's why fill is regularly used with a lambda to generate unique objects.
@shgysk8zer0
@shgysk8zer0 9 месяцев назад
You had me a bit concerned including groupBy() and the Set methods... I was worried the spec had changed yet again. Yes, I knew all of them. I've written polyfills for them, which is why I was worried specs had changed.
@montebont
@montebont 9 месяцев назад
Solution looking for a problem...
@HoangTran-dm9sf
@HoangTran-dm9sf 9 месяцев назад
😂
@vergil_389
@vergil_389 9 месяцев назад
Hello Kyle. Will you avail your course on offer (on a discounted rate) for Christmas. or Before Christmas. 🤞🤞🤞
@leandrohendrix6487
@leandrohendrix6487 9 месяцев назад
I can't use 'with method' in NodeJs. Should I Install some nodeJs package for use it?
@skywizard3319
@skywizard3319 7 месяцев назад
I would really love if you started naming the chapters instead of numbering them
@bronzekoala9141
@bronzekoala9141 9 месяцев назад
Nice, but who th thought "unshift" was a good name for that???
@cbbcbb6803
@cbbcbb6803 8 месяцев назад
What did people do when there was just array?
@sleeplessowl777
@sleeplessowl777 9 месяцев назад
array instanceof Array
@sevgiligencler
@sevgiligencler 9 месяцев назад
Very noob
@АлександрГерасимов-с3щ
Having reduceRight makes it sound like default reduce is wrong
@catto88
@catto88 9 месяцев назад
Wow, didn't knew about .with (this one is very useful!), .groupBy, start/end arguments of .fill, also didn't knew you can add argument like depth to .flat and about Set method, tysm!
@ajedamilola8146
@ajedamilola8146 9 месяцев назад
I wish I had seen this video sooner. This groupBy would have saved me lots of time. I had to do this manually.
@meqdadmoradi
@meqdadmoradi 9 месяцев назад
Please make a video about blobs and array buffer
@shivan2418
@shivan2418 9 месяцев назад
I use lodash for most of this functionality.
@mangadi3859
@mangadi3859 9 месяцев назад
oh sh- i have to change my .sort() to .toSorted()?
@amitd1927
@amitd1927 9 месяцев назад
How about performance of each function
@psydook
@psydook 9 месяцев назад
been waiting for this forever. Thank you man
@vijaykv555
@vijaykv555 9 месяцев назад
First View
@nomadshiba
@nomadshiba 9 месяцев назад
epic
@daedalus5070
@daedalus5070 9 месяцев назад
Prime made a comment recently about some of these and I kind of agree... we need a toMap, toFilter that does mutate the original array. Just to keep JS consistently inconsistent. 😉
@akshaykommu4524
@akshaykommu4524 9 месяцев назад
2nd view
@shirakuyanai4095
@shirakuyanai4095 9 месяцев назад
First time here within 1 minute.
@krzysztofrozbicki1776
@krzysztofrozbicki1776 9 месяцев назад
The main question is - are they faster than simple for() loop ? I have been playing with the js loops lately and it seems that for array of 10 millions random numbers the for() loop is much faster than: filter, find, forEach, map and reduce. And by faster i mean like 10x times faster. The only method that was faster was the build in sort() method. That worked better even then insertion sort/ merge sort/ or quick sort Algorithm made in JS for loop - i am not sure but i suspect this is because of V8 chromium engine which uses C++
@catalintudorciurte309
@catalintudorciurte309 9 месяцев назад
There are some things to unpack here. A for loop is inlined, while the methods call the given function every single time. Also, a for loop gives you the oportunity to mutate the old array, while most of the other functions create a new array every single time
@jasonlough6640
@jasonlough6640 9 месяцев назад
There should be an opposite to .flat(). flat() destroys the structure. What if we were to specify a structure and give an array, like: Array.inflate(arr, structure) where arr = [5,11,87,2] structure = ['age', weight'] which outputs [ { age: 5, weight: 11}, { age: 87, weight: 2}, }
@whosdr
@whosdr 9 месяцев назад
function inflate( values, structure ) { return Object.values( Object.groupBy( values, (e,i)=>Math.floor( i/structure.length ) ) ).map( e => Object.fromEntries( e.map( (v,i) => [structure[i],v] ) ) ); }
@ravisankarp61
@ravisankarp61 9 месяцев назад
Please explain a bit slowly, you are explaining like you are running a sprint.
@windubitably
@windubitably 9 месяцев назад
You can slow the video down. I think his pacing is great.
@dasten123
@dasten123 9 месяцев назад
I really don't see the point of `array.at`.. even for negative indexes, I would prefer `array[array.length - x]` or am I too old-fashioned? :o
@soniablanche5672
@soniablanche5672 9 месяцев назад
it saves you a line of code to store the array in a variable example: const array = getArrayFromApiCall(); array[array.length - 1] vs getArrayFromApiCall().at(-1);
@dasten123
@dasten123 9 месяцев назад
@@soniablanche5672 Ahh!! Yes that makes sense! Thank you, I feel so much better now, haha :D
Далее
Why Signals Are Better Than React Hooks
16:30
Просмотров 478 тыс.
Китайка и Максим Крипер😂😆
00:21
8 Must Know JavaScript Array Methods
10:05
Просмотров 1 млн
5 JavaScript Concepts You HAVE TO KNOW
9:38
Просмотров 1,4 млн
Array Methods in JavaScript | 17 Useful Methods
42:39
Learn TypeScript Generics In 13 Minutes
12:52
Просмотров 266 тыс.
Coding Was HARD Until I Learned These 5 Things...
8:34
Only The Best Developers Understand How This Works
18:32
Why use Type and not Interface in TypeScript
14:12
Просмотров 207 тыс.
The Most Important Skill You Never Learned
34:56
Просмотров 206 тыс.
CSS Tips And Tricks I Wish I Knew Before
12:12
Просмотров 480 тыс.
7 Awesome TypeScript Types You Should Know
8:57
Просмотров 84 тыс.