How can I sort the items by price? It wont work if I run like this sortData('price'), it will work only if I change obj1.type to obj1.price, but I dont want to write duplicate function just because of the key.
function sortData(type) {
var items = [{id:3,price:40}, {id:5,price:100}, {id:1,price:1}];
items.sort(function(obj1,obj2) {
return obj1.type - obj2.type;
})
}