I want to sort a a json array by selected key value.
    var Json = [{
        "post_id": 3,
        "distance": "2.130122"
    }, {
       "post_id": 3,
        "distance": null
    }, {
       "post_id": 4,
        "distance": "4.130122"
    }, {
       "post_id": 5,
        "distance": "3.130122"
    }];
I want to remove the index who have distance:null and want to sort it by distance order. expected json I want like this
 {
        "post_id": 3,
        "distance": "2.130122"
    }, {
       "post_id": 5,
        "distance": "3.130122"
    }, {
       "post_id": 4,
        "distance": "4.130122"
    }
and want to display only post_id as comma seperated **3,5,4**
Here I tried below code.
var Json = [{
        "post_id": 3,
        "distance": "2.130122"
    }, {
       "post_id": 3,
        "distance": null
    }, {
       "post_id": 4,
        "distance": "4.130122"
    }, {
       "post_id": 5,
        "distance": "3.130122"
    }];
Json.sort((a,b)=> (a.distance > b.distance ? 1 : -1))
        var visiblePostId = Json
            .filter(function (item) {
                if (!isNaN(item.distance)) {
                    return item.post_id;
                }
            })
            .map((item) => {
                return item.post_id;
            })
            .join(',');
        console.log(visiblePostId)
<!-- begin snippet: js hide: false console: true babel: false -->Extra help: If somehow duplicate post_id come after sort How can I remove duplicate post id?
 
    