I need to sort the values miles and price based on perMile.
objs[i] = [
    {
        miles : array[i].value1
    },  
    {
        price: array[i].value2
    },
    {
        perMile: array[i].value3
    }
];
I am new to JavaScript
I need to sort the values miles and price based on perMile.
objs[i] = [
    {
        miles : array[i].value1
    },  
    {
        price: array[i].value2
    },
    {
        perMile: array[i].value3
    }
];
I am new to JavaScript
 
    
     
    
    I would suggest
objs[i] = {
    miles : array[i].value1,
    price: array[i].value2,
    perMile: array[i].value3
};
Then you can sort the objs array by the perMile properties of the items like this (assuming they're numbers):
objs.sort(function(a, b) {
    return a.perMile - b.perMile;
});
 
    
    If you can use a library in this instance, you should try Jlinq - http://hugoware.net/Projects/jlinq - It's a library that will allow you to query a Javascript object (associative array) using SQL-esque methods (SORT, SELECT, FROM, etc). The examples on the site will help you to get started. It's a great library, well doucmented, and very lightweight.
