How to remove specfic object in a array using jquery/javascript

63 views Asked by At
var array = [
   {columnsexpo: "First Name", placeholder: true}
   {columnsexpo: "Middle Name / Initial", placeholder: true}
   {columnsexpo: "Last Name", placeholder: true}
   {columnsexpo: "Email", placeholder: true}
   {columnsexpo: "Work Experience / Begin date", placeholder: true}
]
self.firmData.forEach(function (data) {
      $(this.itemlists).append("<div class='item'>" + data.DisplayName + "</div>");
      $("#lstBox1").append($('<option>').text(data.DisplayName).attr('value', data.DisplayName));                   
       self.dt.push(data.DisplayName);
  });

This is my Html code:

<div class="menu">
     <select multiple="multiple" id='lstBox2' >                                    
     </select>
 </div>

i have a array of objects like this in a table as shown in fig.

enter image description here

Now i want to remove selected field for example: if i select Email that field should be deleted from the array and new array should display . I tried this using pop() method this is removing last field but not selected field .

EDIT

I don't need to hardcode deleting value i need to remove selected value

1

There are 1 answers

1
anttud On

let array = [
   {columnsexpo: "First Name", placeholder: true},
   {columnsexpo: "Middle Name / Initial", placeholder: true},
   {columnsexpo: "Last Name", placeholder: true},
   {columnsexpo: "Email", placeholder: true},
   {columnsexpo: "Work Experience / Begin date", placeholder: true}
]

const removeItem = value => array.filter(item => item.columnsexpo !== value)

console.log(removeItem("First Name"))