Unable to remove or cut out a row from JSON

I'm attempting to eliminate a user from a blacklist feature. The goal is to remove the user from the list, splice out the JSON row, and update the mat-table in Angular.

My attempt using

delete this.blacklistGroupTable[i]
does not alter the JSON object as expected.

Another approach I tried was

this.blacklistGroupTable.splice(i, 1)
, but it resulted in an error saying
_this.blacklistGroupTable.splice is not a function

What could be causing this issue?

https://i.sstatic.net/3TUBA.png

unblockUser(userId: string, username: string, i: number) {
    const dialogRef = this.dialog.open(ConfirmationBlacklistComponent, {
      panelClass: "dialogBoxStyler",
      data: {
        username: username
      }
    });

    dialogRef
      .afterClosed()
      .pipe(takeUntil(this.destroy))
      .subscribe(result => {
        if (result) {
          alert("I: " + i);
          this.blacklistGroupTable.splice(i, 1);
          //  delete this.blacklistGroupTable[i];
          console.log("this.blacklistGroupTable");
          console.log(this.blacklistGroupTable);
          this.dataSource.data = this.blacklistGroupTable;

          this.submitListingService
            .sendUserToBlacklist(this.userId, this.bidderId, "UNBLOCK")
            .pipe(takeUntil(this.destroy))
            .subscribe(res => {
              console.log("res");
              console.log(res);
            });
        } else {
          this.blacklistUserDecision = false;
          return;
        }
      });
  }

Answer №1

It seems that your blacklistGroupTable is actually a FileList instead of an array.

Although a FileList is not exactly an Array, it does have similar properties (such as length and numeric indices) which allow us to use Array methods on it:

You can try the following code snippet to log each file separately:

Array.prototype.forEach.call(this.blacklistGroupTable, file => {console.log(file)});

After logging the result using this method: , it appears that your blacklistGroupTable contains a filelist of objects. It is no longer considered an array, so in order to delete elements you can do the following:

const files = [...this.blacklistGroupTable['blacklistGroup']]; 
files.splice(i, 1);

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

Issues with the Array functionality causing unexpected results to be displayed

Within my Angular 4 application, I have an object named allAvailableProviders structured as such - with provider IDs 71 and 72, followed by timestamps in a 24-hour format. 71: {…} 1514678400: […] 0: 800 1: 1300 1515283200: […] 0: 800 ...

Do interfaces in Typescript require nested properties to be mandatory?

My interface contains a nested object: export interface Person { PersonWrapper: { name: string; address: string email?: string; } } When attempting to create an object from this interface, it appears that name is not mandat ...

Is it better to keep a lengthy array in the back-end or front-end storage?

I'm facing a dilemma in my angular application. I have a lengthy array that I need to access easily from the front-end without causing any slowdowns. There are various options available, but I'm unsure which one would be the most efficient. Shoul ...

Modifying a record in Elasticsearch when the document identifier is created automatically

Below is the script I utilize to insert JSON documents into my Elastic Search database: for file in /home/ec2-user/Workspace/met_parts/* do curl -XPOST "http://localhost:9200/ABCD/met/" -d @$file done In my met_parts directory, I have a collection of &a ...

Tips on effectively deserializing JSON elements with identical element collections in C#

I am facing a challenge with deserializing a collection of elements in JSON that contains nested collections of the same elements in C#. How can I achieve this? So far, I have attempted to solve this by creating a C# class for the elements and defining pr ...

Wildcard for keys in JavaScript objects and JSON

I have a JSON object that contains specific key-value pairs, and I am attempting to manipulate strings based on this object. Here is an example of the JSON structure: { "foo %s": "bar %s", "Hello %s world %s.": "W ...

Unable to stop at breakpoints using Visual Studio Code while starting with nodemon

VSCode Version: 1.10.2 OS Version: Windows 7 Profesionnal, SP1 Node version: 6.10.0 Hey there. I'm attempting to debug TypeScript or JavaScript code on the server-side using Visual Studio Code with nodemon. I've set up a new configuration in la ...

navigating through different pages on a react-native application

While building my app in react-native, I encountered some issues with setting up the navigation. I referred to the react-native documentation for guidance, specifically this navigation guide. The guide mentioned passing an object named "navigation" to your ...

Encountering issues with Undefined Subscribe and unable to spy on the onInit method, attempting to spy on the application state service in Angular but it is not recognized

Function Initializing Issue ngOnInit(): void { this.environmentName = this.environment.getGlobalEnvironment().environmentName; this.applicationStateService.LanguageCodeObserver.subscribe((LanguageCode: string) => { this.appLanguage = language ...

Output error messages in Angular form validation explained

Exploring the functionality of this template-driven form in Angular. <form name="editForm" role="form" novalidate (ngSubmit)="save()" #editForm="ngForm"> <input #cardInput type="text" class="form-control" name="name" id="id_name" [(ng ...

What is the best way to transform extensive array information into a URL query parameter?

In my Angular TypeScript web app, I am working with an array containing lat/lng coordinates. const myArr = [ [lat, lng], [lat, lng], ...500 lines of data ] I would like to convert this array into a URL query parameter for users to share or revisit. ...

My Angular project is experiencing issues with Socket.IO functionality

After successfully using a post method in my endpoint, I encountered an error when integrating it with socket io. The error pertained to a connection error and method not being found. Any help or source code provided would be greatly ap ...

Tips for transforming Http into HttpClient in Angular 5 (or higher than 4.3)

I have successfully implemented code using Http and now I am looking to upgrade it to use the latest HttpClient. So far, I have taken the following steps: In App.module.ts: imported { HttpClientModule } from "@angular/common/http"; Added HttpClientModul ...

What is the best way to parse JSON that contains arrays and nested JSON objects?

Starting my journey with Swift has been quite the experience for me. One challenge I currently face is decoding the JSON provided below. The JSON structure consists of two nested JSON objects - the first one being 'validation' which is not relev ...

Generate a fresh column using data from the preceding column

My data frame has a structure similar to the following (with additional columns): srcmacaddr dstmacaddr 00-11-2a-3b-4c-5d 22-33-6e-7f-8g-9h 22-33-6e-7f-8g-9h 00-11-2a-3b-4c-5d 00-11-2a-3b-4c-5d 00-99-5d-4c-3b-2a 00-99 ...

Iterate through a JavaScript grid and display the items

I am attempting to iterate through a JavaScript table, aiming to display the elements located between two selections made by the user. Here is an example of the table structure: if the user selects IDs 2 and 5, the loop should display rows 3 and 4. I trie ...

Strategies for managing recurring identical HTML content

Within my website, I find myself repeating similar content frequently on the same page. For example: <a href="link1"><img src="path1" alt="name1"></a> <a href="link2"><img src="path2" alt="name2"></a> <a href="link3" ...

Submitting sizable tiff documents using nodejs

I'm currently working on a web application with MEAN Stack and Angular 6. My challenge is uploading tiff files (maps) with large file sizes, up to 1.4 GB. I've tried using 'ng2fileUpload' and 'multer', but they are not compati ...

Combining Mouseover, Mouseout, and Click Events in Angular 2+: A Guide for Seamless Interaction with Elements

I am attempting to create a navigation link feature that opens when the user hovers over it, closes when the user moves the cursor away, and toggles when clicked. However, there is a problem with conflicting events causing flickering of the dropdown menu. ...

Tips for Sending Specific Row Information to Server in Ionic 3

Successfully pulled contacts from the device into my list page, but struggling to send specific contact details (name and number) to the server. Can anyone provide guidance on accomplishing this in Ionic? ...