
Common Array Methods in JavaScript
Arrays become much more powerful when we use built-in array methods . These methods allow us to easily add, remove, or transform elements without writing complex loops. In this article, we will learn some commonly used array methods: push() pop() shift() unshift() map() filter() reduce() forEach() These methods help make code shorter, clearer, and easier to maintain. push() and pop() push() The push() method adds an element to the end of an array . Example Before: let fruits = [ " Apple " , " Banana " , " Mango " ]; fruits . push ( " Orange " ); console . log ( fruits ); After: [ "Apple" , "Banana" , "Mango" , "Orange" ] pop() The pop() method removes the last element from an array . Example Before: let fruits = [ " Apple " , " Banana " , " Mango " ]; fruits . pop (); console . log ( fruits ); After: [ "Apple" , "Banana" ] shift() and unshift() shift() The shift() method removes the first element from an array . Example Before: let fruits = [ " Apple " , " Banana " , " Mango " ]; fruit
Continue reading on Dev.to Webdev
Opens in a new tab



