0

I have a list of array which look something like this

{
    "count": 1000,
    "records": [
      {
            "company_id": "1120103661",
            "company_name": "WELLSERVE OILFIELD SERVICES (PVT) LTD",
            "claim_id": "2017\/01\/ISBHHDP00002-2018-00199",
            "user_id": "2017\/01\/ISBHHDP00002-000041",
            "type": "maternity-normal-delivery",
            "claim_category": "Non-Panel",
            "hospital_name": "-",
            "hospital_city": "-",
            "claim_year": "2018",
            "claim_period_start": "2018-02-08 12:02:00",
            "claim_period_end": "2018-02-08 05:02:12",
            "patient_id": "2017\/01\/ISBHHDP00002-157",
            "claim_description": null,
            "status": "settled",
            "created_at": "08-FEB-18",
            "updated_at": "08-FEB-18",
            "submitted_at": "08-FEB-18",
            "claimed_value": "9428",
            "approved_value": "9428",
            "responded_at": "08-FEB-18",
            "settled_at": "08-FEB-18",
            "healthcard_no": "9211-1111-1700-0095",
            "relationship": "Spouse",
            "policy_id": "2017\/01\/ISBHHDP00002",
            "member_name": "Amir Raza Abbasi",
            "patient_name": "Sadia Irshad Kayani",
            "total_limit": "75000",
            "limit_utilized": "9428",
            "remaining_limit": "65572"
        },
        {
            "company_id": "1120103661",
            "company_name": "WELLSERVE OILFIELD SERVICES (PVT) LTD",
            "claim_id": "2017\/01\/ISBHHDP00002-2018-00608",
            "user_id": "2017\/01\/ISBHHDP00002-000065",
            "type": "maternity-caesarean-section-lscs-multiple-births",
            "claim_category": "Non-Panel",
            "hospital_name": "-",
            "hospital_city": "-",
            "claim_year": "2018",
            "claim_period_start": "2018-04-26 12:04:00",
            "claim_period_end": "2018-05-03 05:05:30",
            "patient_id": "2017\/01\/ISBHHDP00002-258",
            "claim_description": "Expired Policy claim as per dr fawad email",
            "status": "settled",
            "created_at": "03-MAY-18",
            "updated_at": "03-MAY-18",
            "submitted_at": "26-APR-18",
            "claimed_value": "15956",
            "approved_value": "15956",
            "responded_at": "26-APR-18",
            "settled_at": "30-APR-18",
            "healthcard_no": "9211-1111-1700-0119",
            "relationship": "Spouse",
            "policy_id": "2017\/01\/ISBHHDP00002",
            "member_name": "Faisal Khan  ",
            "patient_name": "Mahjabeen Zaib",
            "total_limit": "105000",
            "limit_utilized": "15956",
            "remaining_limit": "89044"
        },
        {
            "company_id": "1120103661",
            "company_name": "WELLSERVE OILFIELD SERVICES (PVT) LTD",
            "claim_id": "2017\/01\/ISBHHDP00002-2018-00606",
            "user_id": "2017\/01\/ISBHHDP00002-000072",
            "type": "maternity-caesarean-section-lscs-multiple-births",
            "claim_category": "Non-Panel",
            "hospital_name": "-",
            "hospital_city": "-",
            "claim_year": "2018",
            "claim_period_start": "2018-04-26 12:04:00",
            "claim_period_end": "2018-05-03 05:05:23",
            "patient_id": "2017\/01\/ISBHHDP00002-276",
            "claim_description": null,
            "status": "settled",
            "created_at": "03-MAY-18",
            "updated_at": "03-MAY-18",
            "submitted_at": "26-APR-18",
            "claimed_value": "2817",
            "approved_value": "2817",
            "responded_at": "26-APR-18",
            "settled_at": "30-APR-18",
            "healthcard_no": "9211-1111-1700-0126",
            "relationship": "Spouse",
            "policy_id": "2017\/01\/ISBHHDP00002",
            "member_name": "Yasir Latif",
            "patient_name": "Asma Bibi",
            "total_limit": "105000",
            "limit_utilized": "2817",
            "remaining_limit": "102183"
        }
  ]
}

As in array there are some dates in responded_at

I am taking 2 dates from user. this.from & this.to.

I need to filter this array by 2 dates. Mean only that array will show which is between these 2 dates.

Any one please tell me how can i do this ? Thanks

1 Answer 1

1

You can use Array.filter for that purpose.

Within the callback for Array.filter(), you can convert the responded_at to a JavaScript Date object, and compare it with the from and to dates.

const data = {"count":1000,"records":[{"company_id":"1120103661","company_name":"WELLSERVE OILFIELD SERVICES (PVT) LTD","claim_id":"2017/01/ISBHHDP00002-2018-00199","user_id":"2017/01/ISBHHDP00002-000041","type":"maternity-normal-delivery","claim_category":"Non-Panel","hospital_name":"-","hospital_city":"-","claim_year":"2018","claim_period_start":"2018-02-08 12:02:00","claim_period_end":"2018-02-08 05:02:12","patient_id":"2017/01/ISBHHDP00002-157","claim_description":null,"status":"settled","created_at":"08-FEB-18","updated_at":"08-FEB-18","submitted_at":"08-FEB-18","claimed_value":"9428","approved_value":"9428","responded_at":"08-FEB-18","settled_at":"08-FEB-18","healthcard_no":"9211-1111-1700-0095","relationship":"Spouse","policy_id":"2017/01/ISBHHDP00002","member_name":"Amir Raza Abbasi","patient_name":"Sadia Irshad Kayani","total_limit":"75000","limit_utilized":"9428","remaining_limit":"65572"},{"company_id":"1120103661","company_name":"WELLSERVE OILFIELD SERVICES (PVT) LTD","claim_id":"2017/01/ISBHHDP00002-2018-00608","user_id":"2017/01/ISBHHDP00002-000065","type":"maternity-caesarean-section-lscs-multiple-births","claim_category":"Non-Panel","hospital_name":"-","hospital_city":"-","claim_year":"2018","claim_period_start":"2018-04-26 12:04:00","claim_period_end":"2018-05-03 05:05:30","patient_id":"2017/01/ISBHHDP00002-258","claim_description":"Expired Policy claim as per dr fawad email","status":"settled","created_at":"03-MAY-18","updated_at":"03-MAY-18","submitted_at":"26-APR-18","claimed_value":"15956","approved_value":"15956","responded_at":"26-APR-18","settled_at":"30-APR-18","healthcard_no":"9211-1111-1700-0119","relationship":"Spouse","policy_id":"2017/01/ISBHHDP00002","member_name":"Faisal Khan  ","patient_name":"Mahjabeen Zaib","total_limit":"105000","limit_utilized":"15956","remaining_limit":"89044"},{"company_id":"1120103661","company_name":"WELLSERVE OILFIELD SERVICES (PVT) LTD","claim_id":"2017/01/ISBHHDP00002-2018-00606","user_id":"2017/01/ISBHHDP00002-000072","type":"maternity-caesarean-section-lscs-multiple-births","claim_category":"Non-Panel","hospital_name":"-","hospital_city":"-","claim_year":"2018","claim_period_start":"2018-04-26 12:04:00","claim_period_end":"2018-05-03 05:05:23","patient_id":"2017/01/ISBHHDP00002-276","claim_description":null,"status":"settled","created_at":"03-MAY-18","updated_at":"03-MAY-18","submitted_at":"26-APR-18","claimed_value":"2817","approved_value":"2817","responded_at":"26-APR-18","settled_at":"30-APR-18","healthcard_no":"9211-1111-1700-0126","relationship":"Spouse","policy_id":"2017/01/ISBHHDP00002","member_name":"Yasir Latif","patient_name":"Asma Bibi","total_limit":"105000","limit_utilized":"2817","remaining_limit":"102183"}]};
const from = new Date('10-APR-18');
const to = new Date('30-APR-18');

const res = data.records.filter(obj => new Date(obj.responded_at) > from && new Date(obj.responded_at) < to);
console.log(res);

Sign up to request clarification or add additional context in comments.

3 Comments

Are you referring to my code? If you click "run code snippet", you should see 2 objects in the array
Yes im using same code as you give . i updated json data can you please check in this ?
@ShahnazRaheem Ah, that is because the data format is slightly different. I have updated my code. Let me know how it goes on your end?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.