20+ Must Know Array Methods That Almost Nobody Knows

20+ Must Know Array Methods That Almost Nobody Knows

Web Dev Simplified

7 месяцев назад

88,234 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@FunctionGermany
@FunctionGermany - 05.12.2023 20:30

flatMap is NOT like .flat() .map(), it's like .map() .flat(), very different!!

Ответить
@foxcryptoboss
@foxcryptoboss - 07.12.2023 06:46

something is very off with the camera and sound sync. looks scary.

Ответить
@harmez7
@harmez7 - 07.12.2023 04:25

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.

Ответить
@ahmed37551
@ahmed37551 - 07.12.2023 04:12

i think you have done enough intros kyle. just keep in the bio.

Ответить
@stanmarsh9458
@stanmarsh9458 - 07.12.2023 03:40

groupBy is top!

Ответить
@genyklemberg
@genyklemberg - 06.12.2023 23:29

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😂

Ответить
@BauldyBoys
@BauldyBoys - 06.12.2023 18:28

CSS starts calling everything start and end Javascript starts using left and right. Classic.

Ответить
@quanghungpham269
@quanghungpham269 - 06.12.2023 15:33

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 :)

Ответить
@krzysztofrozbicki1776
@krzysztofrozbicki1776 - 06.12.2023 14:12

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++

Ответить
@catto88
@catto88 - 06.12.2023 13:30

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!

Ответить
@DavideFicano
@DavideFicano - 06.12.2023 11:15

you really need to try console.table() instead of console.log() to show array objects in these awesome videos

Ответить
@ravisankarp61
@ravisankarp61 - 06.12.2023 10:52

Please explain a bit slowly, you are explaining like you are running a sprint.

Ответить
@user-xf8mc8bd2u
@user-xf8mc8bd2u - 06.12.2023 10:33

Is there a new way to get the last item in the array instead of the old array[array.length - 1]?

Ответить
@aundefined
@aundefined - 06.12.2023 08:50

Great video! Keep it up 💯

Ответить
@amitd1927
@amitd1927 - 06.12.2023 08:35

How about performance of each function

Ответить
@justinpatrick1974
@justinpatrick1974 - 06.12.2023 08:01

I knew about half but I always forget about them. Thank you for the refresher. The toSorted() and .toReverse() are my favorite

Ответить
@mfcmasterk
@mfcmasterk - 06.12.2023 06:13

70% watching here is dude i believe, stop winkking!!!! blushed damn it!!!

Ответить
@montebont
@montebont - 06.12.2023 06:04

Solution looking for a problem...

Ответить
@user-ik7rp8qz5g
@user-ik7rp8qz5g - 06.12.2023 05:48

Having reduceRight makes it sound like default reduce is wrong

Ответить
@mecozir
@mecozir - 06.12.2023 05:20

wait general fixed job dom

Ответить
@mecozir
@mecozir - 06.12.2023 05:20

wait general fixed job dom

Ответить
@mecozir
@mecozir - 06.12.2023 05:13

part yield function set key specify task

Ответить
@mecozir
@mecozir - 06.12.2023 05:12

to vs easy enable live

Ответить
@mecozir
@mecozir - 06.12.2023 05:11

post none if code expire

Ответить
@michaelharrington5860
@michaelharrington5860 - 06.12.2023 05:09

`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);

Ответить
@cadekachelmeier7251
@cadekachelmeier7251 - 06.12.2023 04:11

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)

Ответить
@andrillaf
@andrillaf - 06.12.2023 03:50

It’s good to be a developer on Mac😎

Ответить
@FragmentJS
@FragmentJS - 06.12.2023 03:44

hey, did it come into your mind of building hair gel products lately? great tutorials always

Ответить
@shivan2418
@shivan2418 - 06.12.2023 03:35

I use lodash for most of this functionality.

Ответить
@LetrixAR
@LetrixAR - 06.12.2023 03:17

The namings for some of these methods are really confusing

Ответить
@bronzekoala9141
@bronzekoala9141 - 06.12.2023 02:54

Nice, but who th thought "unshift" was a good name for that???

Ответить
@sevgiligencler
@sevgiligencler - 06.12.2023 02:22

Very noob

Ответить
@BokoMoko65
@BokoMoko65 - 06.12.2023 02:01

Is there a method to "flat" an object? That is, to make a deep copy of the entire object made of other objects?

Ответить
@BokoMoko65
@BokoMoko65 - 06.12.2023 01:56

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

Ответить
@BokoMoko65
@BokoMoko65 - 06.12.2023 01:52

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;
}, {});
}

Ответить
@bryson2662
@bryson2662 - 06.12.2023 00:52

Most shocking referral, Kyle uses windows

Ответить
@FIash911
@FIash911 - 06.12.2023 00:23

.groupBy is super useful, but unfortunately still not supported in a lot od environments:/

Ответить
@mateuszroszczyk4380
@mateuszroszczyk4380 - 06.12.2023 00:13

There's one other reliable, though hacky way of checking whether something is an array: Object.prototype.call(people).toString() === "[object Array]";

Ответить
@LawJolla
@LawJolla - 05.12.2023 23:56

This video taught me that someone still uses a PC. Wild.

Ответить
@jischkebd
@jischkebd - 05.12.2023 23:53

you explain these concepts better than the majority of the teachers out there!

Ответить
@dasten123
@dasten123 - 05.12.2023 23:47

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

Ответить
@davidj6755
@davidj6755 - 05.12.2023 23:30

I’m excited about the set theory operators. I hope that eventually gets full support across major browsers.

Ответить
@industrydzina
@industrydzina - 05.12.2023 23:13

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...

Ответить
@magnanova
@magnanova - 05.12.2023 23:12

It's about time they added those Set difference/intersection methods!

Ответить
@mangadi3859
@mangadi3859 - 05.12.2023 23:07

oh sh- i have to change my .sort() to .toSorted()?

Ответить
@olegkravchenko9655
@olegkravchenko9655 - 05.12.2023 23:02

С*ка, до слёз! Даже плюсик поставил от нахлыва чуйств :D

Ответить
@Wakedaddy87
@Wakedaddy87 - 05.12.2023 22:38

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!

Ответить