Eliminate a particular attribute from an array of objects

https://i.sstatic.net/O7lKv.pngHaving an issue with removing an item from an array object based on a specific property. Let me explain.

  delColumn($event: any, el: any) {
if ($event.target && el > -1) {
  var colId: string = this.receivedData[0].value.columns[el].id;
  var obj = this.receivedData[0];
  obj.values.columns = obj.values.columns.filter(s => s.id != colId);
  obj.values.rows.forEach(s => {
    delete s.Col_1;
    return s;
  });
}

}

My goal is to remove a specific column and its associated rows when the Delete Column action is triggered by clicking.

Appreciate the assistance in advance.

https://i.sstatic.net/tX2aC.png

Answer №1

  data=[{Name:"John",Age:25},
        {Name:"Jane",Age:30},
        {Name:"Bob",Age:35},
        {Name:"Alice",Age:40}];

  newData=this.data.map(item=>{
     return this.removeKey(item,"Age");
  })
  removeKey(object, key){
    const {[key]: removedKey, ...remainingKeys} = object;
    return remainingKeys;
  }
  initialize()
  {
     console.log(this.data);
     console.log(this.newData);
  }

Answer №2

Employ the methods filter and forEach

obj.data.columns = obj.data.columns.filter(item => item.id !== "Col_1");
obj.data.rows.forEach(row => {
   delete row.Col_1;
   return row;
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to enable CORS with Laravel for AngularJS 'Access-Control-Allow-Origin'

Recently, I installed Laravel CORS by barryvdh. While the module appears to be functioning correctly, I am still encountering the Access-Control-Allow-Origin error. When attempting to make a request to , I receive the error message stating that no &ap ...

Troubleshooting: Unable to load template file content in AngularJS ng-view

Setting up a demo angular app has been quite the challenge for me. Despite my efforts, the content from my partial file (partials/test.html) is not loading into the layout file as expected. Below is a snippet of my index.html: <!DOCTYPE html> <ht ...

Convert Ajax null value to NoneType in web2py

Every time I save information on a page, an AJAX request is sent with all the necessary data to be stored in the database. The format of this data looks similar to this example: {type: "cover", title: "test", description: null, tags: null} However, when ...

Cannot access Injectable service in Angular2

In the angular2 application, there is a service named HttpClient. The purpose of this service is to include an authorization header in every request sent by the application to endpoints. import { Injectable } from '@angular/core'; import { He ...

While using Angular CLI on GitLab CI, an error occurred indicating that the custom rule directory "codelyzer" could not be

ng lint is throwing an error on Gitlab CI stating: An unhandled exception occurred: Failed to load /builds/trade-up/trade-up/common/projects/trade-up-common/tslint.json: Could not find custom rule directory: codelyzer. The strange thing is that ng lint ru ...

What is the most effective method for iterating through millions of records in Angular or TypeScript?

Looking for a solution to load multiple multi-select drop-downs with cascading effect based on related data. I am dealing with millions of records retrieved from an API, some of which are duplicates in one column but unique when considering all columns. ...

Guidelines on resolving the issue of Unsupported platform for [email protected]: requested {"os":"darwin","arch":"any"} (existing: {"os":"win32","arch":"x64"})

Trying to install Parallelshell but encountering a persistent warning. I've checked the package file multiple times without finding a solution. Can someone assist me with this issue? ...

Implementing real-time time updates using php ajax technology

It's fascinating how websites can update the time dynamically without using ajax requests. I currently have a comment system in place. $('#comment').click(function(){ $.post(url,{ comment : $(this).siblings('textarea.#commen ...

What measures can be taken to prohibit a user from accessing a client-side HTML file using express?

I am currently developing a task management application called "todolist." In my node.js code, I utilize express and grant it access to my directory named Client: var app = express(); app.use(express.static(__dirname + "/Client")); The contents of my Cl ...

My method for updating form input properties involves switching the disable attribute from "false" to "true" and vice versa

I have a form that uses Ajax to submit data. Once the user submits the form, the text is updated to indicate that the data was sent successfully, and then the form is displayed with the fields filled out. I want to display the form but prevent users from r ...

Troubleshooting: Missing MapState in Vuex4 for Vue3 within an MVC project

Within my MVC project, I have successfully integrated Vue3 with Vuex4. However, I have encountered an issue specifically related to the mapState function. Upon using the following import statements, an error is triggered: import Vue from 'vue'; ...

Tips for accessing a unique window name in JavaScript

How can I make window.name persist between page refreshes? I need to use window.name to differentiate between multiple browser windows, allowing each one to display distinct data while sharing the same URL. However, my problem is that the value of window ...

Unable to execute jQuery on dynamically loaded AJAX page

Currently, I am utilizing jQuery to dynamically load a page via AJAX using the $.ajax method (specifically test.html). This HTML document consists of several buttons with associated animations when clicked (also utilizing jQuery). The .click() properties a ...

A guide to categorizing and tallying JSON data based on multiple keys within the past 30 days using JavaScript/jQuery

I am facing an issue while trying to display a chart and extract specific data from an array. My goal is to generate a chart based on three columns in a JSON array: Source, Campaign, and Date. The process involves grouping the data, counting it, and then ...

Utilizing React and Google Code to Enhance Lead Conversion Pages

I have developed a basic react application featuring a contact form. Upon submission, I aim to display the Google Code for the lead Conversion Page within the application. <!-- Google Code for Purchase Conversion Page --> <script type="text ...

AngularJS: Creating a one-to-one relationship between JavaScript objects within the same array

I am trying to establish a connection between two objects in the same array to indicate that one task must be completed before the other can begin. I attempted to use AngularJS's ng-options directive by setting the child object as a property of the pa ...

Solving Typing Problems in React TypeScript with "mui-icons" Props

I have a small compost project with only an App.JSX file that is functioning perfectly, but now I need to convert it to App.TSX. After changing the extension to .TSX, I encountered two errors that I'm unsure how to resolve. function MyComponentWithI ...

Populate dropdown options in Angular dynamically

I am attempting to populate a dropdown with relevant data based on the selection from another dropdown. Here is my code snippet: HTML <select class="form-control" (ngModelChange)="onChange($event)"> <option disabled="true">{{ txtOptDefault ...

Experiencing difficulties when attempting to show or hide elements using jQuery

I spent several hours trying to figure this out and couldn't get it right. Is it feasible to create a jQuery script that will perform the following action when a <span> element is clicked: Check if any of the <p> elements are current ...

What is the correct way to handle Vue props that include a dash in their name?

I am currently working on a project using Vue. Following the guidelines of eslint, I am restricted from naming props in camel case. If I try to do so, it triggers a warning saying Attribute ':clientId' must be hyphenated. eslint vue/attribute-hyp ...