-1

I have an object of object array in json format.I want to remove one object form this object array using vuejs.

vuejs

export default {
  components: { leftmenu, countDown, timer, Header },
  data() {
    return {
      this.orders = {"data":{"175":{"details":[{"order_id":175,"item_id":1,"item_name":"pizza"},{"order_id":175,"item_id":2,"item_name":"burger"}]},"173":{"details":[{"order_id":175,"item_id":1,"item_name":"pizza"}]}}}
    };
  },
}

I have tried to remove object which have key 175 using below code.But did not work.

        const filtersList = Object.keys(this.orders.data).filter(
         (element) => element !== index
       );
       this.orders = filerslist
1
  • Object.keys(this.orders) will only return 'data' Commented Apr 11, 2022 at 7:02

1 Answer 1

2

You can use the delete keyword (documentation here) to remove keys from objects

const orders = {
  "data": {
    "175": {
      "details": [{
        "order_id": 175,
        "item_id": 1,
        "item_name": "pizza"
      }, {
        "order_id": 175,
        "item_id": 2,
        "item_name": "burger"
      }]
    },
    "173": {
      "details": [{
        "order_id": 175,
        "item_id": 1,
        "item_name": "pizza"
      }]
    }
  }
}

delete orders.data["175"]
console.log(orders)

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

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.