DEV Community 👩‍💻👨‍💻

Oluwanifemi Latunde
Oluwanifemi Latunde

Posted on

Remove Element

Today is day 2 of the #I4G10DaysOfCodeChallenge and the challenge for today was to remove a specific element from an array or list.

I solved the challenge using python and JavaScript.
I used the inbuilt remove method for python and the inbuilt splice method for JavaScript.

Image of the solution using Python3

I looped through each content of the array and did a check to know if the specific number was reached, if it was then it should be removed from the array.

The splice method of JavaScript can be used if you are aware of the value you wish to delete from an array. You must first determine the target item's index. Then, you start by removing one element while using the index as the start element. To avoid skipping the next member in the array when you wish to remove many elements, simply decrement the index variable.

Image of the solution using JavaScript

Thank you.

Latest comments (4)

vishwastyagi profile image
Vishwas Tyagi

Congratulations! Keep going.

nifilat profile image
Oluwanifemi Latunde

Thank you so much

khojo_kwofie profile image
Evans Kojo Kwofie

Good simple solve!

themfon profile image

Doings! 🤲🏾

In defense of the modern web

I expect I'll annoy everyone with this post: the anti-JavaScript crusaders, justly aghast at how much of the stuff we slather onto modern websites; the people arguing the web is a broken platform for interactive applications anyway and we should start over;

React users; the old guard with their artisanal JS and hand authored HTML; and Tom MacWright, someone I've admired from afar since I first became aware of his work on Mapbox many years ago. But I guess that's the price of having opinions.