What is the process for removing a specific column (identified by its key value) from a JSON table using JavaScript and Typescript?

[{
    "name": "employeeOne",
    "age": 22,
    "position": "UI",
    "city": "Chennai"
},
{
    "name": "employeeTwo",
    "age": 23,
    "position": "UI",
    "city": "Bangalore"
}
]

If I remove the "Position" key and value from the JSON, the updated result will be:

[{
    "name": "employeeOne",
    "age": 22,
    "city": "Chennai"
}, {
    "name": "employeeTwo",
    "age": 23,
    "city": "Bangalore"
}]

Suppose we have a list of employees in a table and I want to delete only the position column for all employees. How can this be achieved using JavaScript and TypeScript?

I attempted:

const output = delete employee.position

but encountered an error.

Answer №1

const team = [{
                "name": "workerOne",
                "age": 28,
                "role": "Developer",
                "city": "Mumbai"
            },
            {
                "name": "workerTwo",
                "age": 29,
                "role": "Designer",
                "city": "Delhi"
            }
          ];

team.forEach( person => {delete person.city;});

console.log(team);

Answer №2

Within this collection are numerous objects. Your task is to iterate through each object, removing the specific property within them one by one.

Answer №3

check out the remove operation

algorithm:

for each item in recordArray
{
remove item["location"];
}

it also functions with:

item[location]
item.location

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

Text from the GET request is not being displayed in the textbox, although it is appearing in the div when using Jquery and Ajax

Currently, I have a webpage that features a text box which can be updated in real-time as the user types and is immediately saved to the database. Here is the code for my textarea: <textarea id="text"></textarea> My objective: If a user ope ...

Webpack encounters an error while attempting to load Bootstrap v4.0.0-beta

I've encountered an issue with my webpack configuration and Bootstrap v4.0.0-alpha.6 that was working fine until I attempted to switch to v4 beta. Unfortunately, I can't seem to get it working properly now :( Here is a snippet of my config: w ...

Diving deeper into the functionalities of the express.js response module

I am currently developing an application that requires the use of two different templating languages. The code snippet below demonstrates how I am incorporating Jade and Lodash templates: app.get('/route1', function(req, res) { res.render(&apos ...

The Disable Button is malfunctioning as the text is deleted but the button remains enabled

One issue I am facing is that even after removing the numbers from the textboxes, the submit button remains enabled. Initially, when I enter inputs in the textbox, it enables the button, but even after removing a number, the button stays enabled. This is ...

incorporate setInterval() with a dynamic variable serving as the millisecond value

During initialization of the component, a value is fetched from the ngrx store and used as a configuration. this.storeService.selectMConfig().subscribe(res => { if (!res) return; const refreshValue = Number(res.items[0].value) * ...

Can SailsJS be used exclusively for API processes?

Can SailsJS be used solely as an API? After downloading the Sails project, is it possible to exclude the views and focus only on utilizing Sails as an API? ...

What is the best way to toggle the Angular date picker on and off for a specific date with Angular Material?

I need to display the start date and end date where the start date is in format dd/mm/yyyy, for example 10/09/2020, and the end date should be yesterday's date, i.e., 09/09/2020. All other dates should be disabled. What steps should I take to impleme ...

Transfer razor javascript calls in Blazor WebAssembly to a separate class

Scenario Description Greetings, I am currently working on a Blazor WebAssembly project that involves JavaScript interop. Initially, I had this functionality working in a .razor page. However, I now intend to encapsulate and centralize these JavaScript inv ...

Steps for implementing a delete button in a custom table on yii

I've encountered an issue with a form that uses ajaxSubmitButton to add product items to an HTML table. The ajaxSubmitButton successfully adds items using AJAX to update the table's <tr> and <td> elements. I've also included a de ...

The knockout click event isn't functioning properly for a table generated by ko.computed

My goal is to connect a table to a drop-down menu. Here are the key points of what I'm trying to achieve: The drop-down should list MENUs. Each MENU can have multiple MODULES associated with it, which will be displayed in the table based on the ...

"Setting an index to a button's ID using Jquery: A step-by-step guide

My goal is to assign incrementing index values to button IDs in a loop. For example, if the first button has an ID of 'unique', the second button should have an ID of 'unique0', and the third button should have an ID of 'unique1&ap ...

Dynamic Angular component loading with lazy loading

In my Angular 4.1.3 project, I am currently developing a mapping application that incorporates lazy-loading for various tool modules. At present, the tools are loaded within the map using a router-outlet. However, I now need to expand this functionality to ...

ScriptManager is not accessible in the current ASP.Net Core Razor Page context

I'm facing an issue where I have a view (such as Index.cshtml) and a page model (like Index.cshtml.cs). In the view, there's a JavaScript function that I want to call from the OnPost() method in the page model. I tried using ScriptManager for thi ...

Refreshing a page will disable dark mode

I'm in the process of implementing a dark mode for my website using the code below. However, I've encountered an issue where the dark mode resets when refreshing the page or navigating to a new page. I've heard about a feature called localst ...

Animating shapes in Three.js

Is it possible to animate the underlying shape of a mesh created using Three.js by drawing a shape and extruding it? For example: drawShape: function(){ var shape = new THREE.Shape(); shape.moveTo(0, 0); shape.arc(0,0,30,0,(Math.PI*1.9),true) ...

"Quotes are essential in Javastript syntax for specifying string values

I need to implement a JavaScript syntax to generate unique URLs for each image. The Robohash website provides random robot images based on different URL endings. I tried the code below, but it seems like ${props.id} is being interpreted as part of the UR ...

The ngMessages validation feature in AngularJS fails to remove error messages from the CSS styling

Can anyone help me figure out why I keep getting a red color underline error even though there is no actual error and validation is successful? https://i.sstatic.net/AESLl.png I created my own directive to validate passwords and I am using Angular materi ...

What is the formula to determine the sizes of grandchildren div containers?

Hey everyone, I'm having some trouble with my jQuery code and I can't seem to figure out what's going on. Here's the scenario: I'm creating a few divs (based on entries from MySQL) and I'd like to show you the end result: ...

How to display an array with JSON objects in Angular 4

Looking to display specific data from an array in my .html file that originates from my .ts file: myArray: ["03/05/2018", "2:54", "xoxo", "briefing", "your", [{ "Id": "1", "Time": "20:54", "Topic": "mmmmm", "GUEST1": { "Role": "HS" ...

Generating an array of elements from a massive disorganized object

I am facing a challenge in TypeScript where I need to convert poorly formatted data from an API into an array of objects. The data is currently structured as one large object, which poses a problem. Here is a snippet of the data: Your data here... The go ...