Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Sorting an array of JavaScript objects

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 230
    Comment on it

    Hello friend,
    I have a javascipt array object. Now i will try to sort price in this array.

    For Example:

    var data = [
        {
            "h_id": "3",
            "city": "Dallas",
            "state": "TX",
            "zip": "75201",
            "price": "162500"
        }, {
            "h_id": "4",
            "city": "Bevery Hills",
            "state": "CA",
            "zip": "90210",
            "price": "319250"
        }, {
            "h_id": "5",
            "city": "New York",
            "state": "NY",
            "zip": "00010",
            "price": "962500"
        }
    ];
    

    Javascript sort function sorts the value of array by passing index key. It will sort price as ascending order by using below code.

    data.sort(function(a, b) {
        return parseFloat(a.price) - parseFloat(b.price);
    });

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: