0

My array is as such

 "regions": [
            {
                "Id": 1,
                "code": 1,
                "name": "Trivandrum",
                "Categories": [
                    {
                        "Id": 1,
                        "category_id": 1,
                        "region_id": 1,
                        "ref_count": 2,
                    }
                ],
                "Shops": [
                    {
                        "Id": 33,
                        "is_enabled": true,
                        "is_setup_complete": false,
                        "approval_time": 10,
                        "packaging_time": 30,
                        "erp_ref": "45645655",
                        "priority": 0,
                        "admin_id": 11,
                        "region_id": 1,
                    },
                    {
                        "Id": 34,
                        "is_enabled": true,
                        "is_setup_complete": false,
                        "approval_time": 10,
                        "packaging_time": 30,
                        "erp_ref": "4524645",
                        "priority": 0,
                        "admin_id": 11,
                        "region_id": 1,
                    },
                    
                ]
            }
        ]

I want to completely remove the Shops from the array.How can I do it in JavaScript?

1

3 Answers 3

3

You can do this simply with the delete operator which removes a property from an object. In this case, you can use:

delete regions.regions[0].Shops;

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

Comments

0

Use delete to get rid of an object, or maybe multiple if you wanted to.

"regions": [
            {
                "Id": 1,
                "code": 1,
                "name": "Trivandrum",
                "Categories": [
                    {
                        "Id": 1,
                        "category_id": 1,
                        "region_id": 1,
                        "ref_count": 2,
                    }
                ],
                "Shops": [
                    {
                        "Id": 33,
                        "is_enabled": true,
                        "is_setup_complete": false,
                        "approval_time": 10,
                        "packaging_time": 30,
                        "erp_ref": "45645655",
                        "priority": 0,
                        "admin_id": 11,
                        "region_id": 1,
                    },
                    {
                        "Id": 34,
                        "is_enabled": true,
                        "is_setup_complete": false,
                        "approval_time": 10,
                        "packaging_time": 30,
                        "erp_ref": "4524645",
                        "priority": 0,
                        "admin_id": 11,
                        "region_id": 1,
                    },
                    
                ]
            }
        ]
delete(region.Shops);
console.log(region);

Comments

0

let regions = [
            {
                "Id": 1,
                "code": 1,
                "name": "Trivandrum",
                "Categories": [
                    {
                        "Id": 1,
                        "category_id": 1,
                        "region_id": 1,
                        "ref_count": 2,
                    }
                ],
                "Shops": [
                    {
                        "Id": 33,
                        "is_enabled": true,
                        "is_setup_complete": false,
                        "approval_time": 10,
                        "packaging_time": 30,
                        "erp_ref": "45645655",
                        "priority": 0,
                        "admin_id": 11,
                        "region_id": 1,
                    },
                    {
                        "Id": 34,
                        "is_enabled": true,
                        "is_setup_complete": false,
                        "approval_time": 10,
                        "packaging_time": 30,
                        "erp_ref": "4524645",
                        "priority": 0,
                        "admin_id": 11,
                        "region_id": 1,
                    },
                    
                ]
            }
        ]

for(let region of regions) {
  delete region.Shops;
 }
 
 console.log(regions);

Comments

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.