Sorting an array in Javascript

Sorting an array ascending and descending in Javascript for a specific array key such as price or name. The function to sort the array for price ascending or descending. As…