Skip to main content

Posts

Showing posts with the label array methods

JavaScript Basic: Six Most Simple Array Methods Make Our Life Easier

Arrays come with many built-in methods, and I just learn six most simple methods that can make our life easier. Push We use push to add to the end of an array. For example, if I want to add another letter at the end of array, instead of write letters[4],  I can write: Image an array contains 100+ data, we don't have to count index every time we want to add a new data in the array. Pop We use pop to remove the last item in an array. If I want to remove the letter "D" from the array, I can write: Unshift We use unshift to add a new item to the front of an array. Instead of add letter "E" at the end of the array, I can add "E" in front of the "A". Shift We use shift to remove the first item in an array. If I want to remove the letter "A" in the array, I can write: IndexOf() We use indexOf() to find the index of an item in an array. If I want to find the index of letter "C", I can writ...