Using the
Array.push()
method, you can push elements onto the end of a given array instance. That's handy for when you're first building an array, and assuming that you're not maintaining the sort order of the array. But what if you've already got an array, one that's populated with elements? In this case,
Array.splice()
is your friend — you use this to insert elements at the specified index position. If all you're doing is trying to add elements to an array while maintaining the sort order, you can use Lodash.