Delete an entry from array of objects on button click

Gaurav

I am given the following object, I need to delete a destination_field and then loop that new object inside HTML

var columnDropdownStatesJobDetails = {header: "Collection Status", field: "collection_status"}
          {header: "Hostname", field: "hostName"}
          {header: "Device Id", field: "deviceId"}
          {header: "Sensor data", field: "sensorData"}
          {header: "Destination", field: "destination_id"}
          {header: "Last Reported Time", field: "lastReportedTime"}

following is what I did

private setDestColChecked(tabSelected, oldVal, newVal) {
  debugger;
  this.newObj= this.columnDropdownStatesJobDetails;
  if (this.columnDropdownStatesJobDetails.length > 0) {
    this.newObj.filter(function(e) {
      if (tabSelected === 'destinationTab' && (e.field === 'destination_id') && (e.visible === oldVal)) {
        e.visible = newVal;
      } else { 
        // here is my attempt to delete this field
        if (e.field === 'destination_id') {
          delete e.field;
          // return e.field !== 'destination_id';
          // delete this.columnDropdownStatesJobDetails.destination_id;
        } 
      }
    });
    console.log(this.newObj);
  }
}

What am I doing wrong here?

<ng-container *ngFor='let col of columnDropdownStates'>
                        <label *ngIf='col' class="checkbox">
                            <input type="checkbox" id={{col.field}} [checked]="col.visible" name={{col.header}}
                                   (change)="onColumnCheckboxChange($event)"/>
                            <span class="checkbox__input"></span>
                            <span class="checkbox__label">{{col.header}}</span>
                        </label>
                    </ng-container>
vizsatiz

Bit confused about what you are trying to do, but let me give it a try. You are doing a filter here. So you just need to write your filter condition and that item will not be there is your output list:

var x = [1, 2, 3, 4]
var y = x.filter(function(e){e > 3})
console.log(y) // y = [4]

But if you want to change something by iterating a foreach should work. Am not clear about the type of columnDropdownStatesJobDetails, if its a map you can just delete columnDropdownStatesJobDetails['destination_id']

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to add separate strings to array from button click and delete strings from array with a different button click?

From Dev

Delete last object from the array of objects.

From Dev

How to remove an item from the array on button click

From Dev

Delete item with Button click

From Dev

How to delete empty objects from an Array in javascript?

From Dev

PHP delete row from a table with button click

From Dev

How to delete objects from react state hook array with a button click

From Dev

How to delete from the array, with date id, and click?

From Dev

Delete button element from array loop Angular

From Dev

JS Loop through an array of objects of an array of objects to delete entry

From Dev

On click get button values from array javascript?

From Dev

Deleting an object from an array on click of a button

From Dev

Delete same objects from an array as another array of objects

From Dev

Sort Array and delete the reamining objects from it

From Dev

Delete row from table on corresponding delete button click

From Dev

Can a tkinter button return a value from an entry on-click?

From Dev

Click on an element and delete it from an array

From Dev

Delete database entry on click of delete button. The data is showed through loop from database

From Dev

How to delete an entry from an array using submit button(php)

From Dev

Button to delete table entry

From Dev

Delete an object from a nested array of objects

From Dev

how to delete duplicate records from array of objects?

From Dev

Delete an entry from firebase realtime database with a click of a button

From Dev

Delete object from array on click

From Dev

Trying to delete an element from an array with objects

From Dev

How do you delete a multidimentional array from localstorage on button click?

From Dev

What is the best way to delete objects from Array

From Dev

Removing objects from array with the click of a button React

From Dev

Delete item from array inside objects

Related Related

  1. 1

    How to add separate strings to array from button click and delete strings from array with a different button click?

  2. 2

    Delete last object from the array of objects.

  3. 3

    How to remove an item from the array on button click

  4. 4

    Delete item with Button click

  5. 5

    How to delete empty objects from an Array in javascript?

  6. 6

    PHP delete row from a table with button click

  7. 7

    How to delete objects from react state hook array with a button click

  8. 8

    How to delete from the array, with date id, and click?

  9. 9

    Delete button element from array loop Angular

  10. 10

    JS Loop through an array of objects of an array of objects to delete entry

  11. 11

    On click get button values from array javascript?

  12. 12

    Deleting an object from an array on click of a button

  13. 13

    Delete same objects from an array as another array of objects

  14. 14

    Sort Array and delete the reamining objects from it

  15. 15

    Delete row from table on corresponding delete button click

  16. 16

    Can a tkinter button return a value from an entry on-click?

  17. 17

    Click on an element and delete it from an array

  18. 18

    Delete database entry on click of delete button. The data is showed through loop from database

  19. 19

    How to delete an entry from an array using submit button(php)

  20. 20

    Button to delete table entry

  21. 21

    Delete an object from a nested array of objects

  22. 22

    how to delete duplicate records from array of objects?

  23. 23

    Delete an entry from firebase realtime database with a click of a button

  24. 24

    Delete object from array on click

  25. 25

    Trying to delete an element from an array with objects

  26. 26

    How do you delete a multidimentional array from localstorage on button click?

  27. 27

    What is the best way to delete objects from Array

  28. 28

    Removing objects from array with the click of a button React

  29. 29

    Delete item from array inside objects

HotTag

Archive