может так?
<head>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.9.0.min.js"></script>
<script>
var headers = ['Номер', 'Название', 'Количество', 'Цена'];
var fieldsNames = ['id', 'name', 'count', 'price'];
var orders = [
{
id: 1,
name: "Book",
count: 3,
price: 157
},
{
id: 2,
name: "Pen",
count: 4,
price: 85
},
{
id: 3,
name: "Phone",
count: 1,
price: 464
},
{
id: 4,
name: "Pencil",
count: 65,
price: 314
},
{
id: 5,
name: "Sharpener",
count: 6,
price: 96
}
];
</script>
</head>
<table>
<tr>
<th class='id'>Номер</th>
<th class='name asc'>Название</th>
<th class='count'>Количество</th>
<th class='price'>Цена</th>
</tr>
</table>
<script>
$('th').click(function(){
var key = $(this).attr('class').replace(' asc', '').replace(' desc', '');
orders.sort(function (a, b) {
return b[key] - a[key];
});
//console.log(orders)
console.log(JSON.stringify(orders))
})
</script>