JavaScript Problem: Remove Every nth Element from an Array

preview_player
Показать описание
A question on the YouTube channel recently prompted this tutorial on this JavaScript problem. We are going to look at how we can remove every second or third item from an array.

Would you like to help keep this channel going?

Tutorials referred to in this video:

For more resources on JavaScript:

#javascript #AllThingsJavaScriptLLC
Рекомендации по теме
Комментарии
Автор

Such a great tutorial. So very helpful, thank you! I'm in the habit of watching and then practicing, and I added this method of comparison to view the two arrays in a table;

const compare_array = [my_array, my_filtered_array];
output.table(compare_array)

karlstenator
Автор

I've been watching your videos recently and your explanations are great. Thanks so much!

QkiJose
Автор

best yt channel for js... pure core things. Thank you for all videos man!

kojisnjak
Автор

great tutorial!

how about the reverse, adding items every nth element?

alexanderr
Автор

(idx + 1) not needed. idx % 3 !== 2 should work as well when we want to remove every third element. Or idx % 4 !== 3 - when every fourth.

trusabaka
Автор

nums = nums.filter(item => item) has a TREMENDOUS problem that nobody spotted. What if item = 0? You conveniently did not include 0 in the nums array. :)

trusabaka
Автор

Why you are not posting videos nowadays ? So disappointed Steven 😔

arunkaiser