How to eliminate properties from a nested array using D3

I've been attempting to filter out specific attributes from an array using D3. The array consists of values from a CSV file.

Everything went smoothly for a small CSV file when I did it like this:

d3.csv("foods.csv", function(data) {
data.forEach(function(v){ delete v.name });
data.forEach(function(v){ delete v.created_at });
});

This is how the first array appeared:

However, when I tried to apply the same concept to a larger CSV file, I encountered an error message stating: "DevTools was disconnected from the page. Once the page is reloaded, DevTools will automatically reconnect." This is what the second array looked like. https://i.sstatic.net/RbGvF.png

Why isn't this method working for the second array? Could it be due to the size of the array, or should I attempt to address the values recursively? I already tried implementing it in the following manner:

function deleteCitation(v) {
if(Object.prototype.toString.call(v) === '[object Array]' ) {
    v.forEach(deleteCitation);
}
else {
    delete v.citation;
 }
}

d3.csv("compounds_foods.csv", function(data) {
   data.forEach(deleteCitation);

   print(data);
});

Answer №1

I have never encountered a situation where I had to load a CSV file with 740,000 rows. However, there are a few alternatives that you can consider:

One option is to use a row conversion function or an accessor function like this:

d3.csv("foods.csv", modifyData, function(data) {
//continue with the code

You can then define the conversion function as follows:

function modifyData(d){
    delete d.name;
    delete d.created_at;
    return d;
}

While I haven't run any benchmarks, it's possible that the conversion function may take a similar amount of time as using your forEach loop (since they essentially do the same thing). However, it could be worthwhile to test if this approach is faster than calling your modifyData function for each object in the data array.

Another simpler alternative is to keep those two properties in the data and simply not use them.

When loading a CSV into your data array, you don't necessarily need to utilize every property within each object for your visualization. You can choose to ignore certain properties. It's possible that spending processing power on manipulating such a large array might be more efficient than removing those extra properties altogether.

The third alternative would be the most logical one: considering the fact that it's highly unlikely that you would actually use all 740,000 objects in a data visualization, you should contemplate filtering, reducing, or cropping the CSV before sending it to the client side.

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

Convert millimeters to inches with a unique AngularJS filter that activates on click

I am currently working on a UI that requires users to enter dimensions for width and height. Within the UI, there are 2 buttons available - one for 'mm' and the other for 'inches'. When either of these buttons is pressed, the active cl ...

What is the best way to bypass array values in PHP?

Seeking assistance with an array: Array ( [0] => 2 [1] => 2 [2] => 1 [3] => 1 [4] => 2 [5] => 2 ) Exploring the use of a foreach loop: foreach( $valortot as $key => $m ) { $valortot[$key]; echo $valortot[$key]; echo "<br>"; } T ...

Dealing with Socket.io connection problems on Node.js and Windows 10 platform

Just starting with nodejs and recently set it up on my Windows10 machine. I decided to create a folder within Nodejs and included a server.js file. Next step was installing socket.io using the command "npm install socket.io". Here's a snippet of what ...

display the values of the array object within the ajax success callback

When I receive the result, it looks like this https://i.sstatic.net/q4iUb.png But now I want to display that content inside a dropdown box with option values. How can we accomplish that? My current approach is as follows: var data = data.user_contacts ...

Identifying browsers with Zend Framework versus JavaScript

Currently, I am working on developing an application that demands the capability to upload large files. After much consideration, I have opted to utilize the FormData object as it allows me to provide progress updates to the user. Sadly, Internet Explorer ...

Next-auth custom authentication provider with unique backend

I am currently experiencing an issue with sessions while using auth authentication. My next-auth version is 4.0.0-beta.4 (also tried beta.7 with the same results). My backend utilizes a custom JWT token system that returns an object containing an access t ...

When using `setState()`, ensure that you are updating a component that is already mounted or in the process of mounting. If you receive this error, it

When using WebSocket to communicate with my server, I call the handleSubmit() function to send data and update my state based on the received response. Everything works fine initially. Upon calling componentWillUnmount, I stop sending data to the websocke ...

Enhancements in Converting JSON Objects to HTML Lists Using jQuery

I have created a function that converts a multi-dimensional JSON object into an HTML list. You can check it out here: http://jsfiddle.net/KcvG6/ Why is the function rendering the lists twice? Update: http://jsfiddle.net/KcvG6/2/ Are there any impro ...

Having trouble getting webpack to transpile typescript to ES5?

Despite following official guides and various tutorials, I am still facing an issue with compiling my code to ES5 using TypeScript and webpack. The problem is that the final bundle.js file always contains arrow functions. Here is a snippet from my webpack ...

Using ng-repeat in conjunction with ui-router conditions

Utilizing ui router ($routeprovider and $locationprovider) for angular js, I am looking to adjust the array being looped through in an ng-repeat based on the current url/route. Despite browsing similar threads on stack, I have not found a precise solution ...

Utilize a drop-down selector in JavaScript to search and refine the results

Looking for a way to enhance your product search form? Consider adding an option to select a specific shop from the dropdown menu. This will allow users to search for products within a particular store if desired. <form action="#" method="get"> &l ...

JavaScript for automatic file reading

I'm currently working on a personal file storage website as part of a practice project. The code itself is functional, but I'm facing the challenge of managing a large JSON file containing the names of all the files I want to display on the websi ...

Angular 2 doesn't reflect changes in component variables in the view until mouseover happens

Since updating from angular2-alpha to the latest version, I've noticed that when a boolean value changes in my *ngIf directive, it doesn't reflect in the view until certain actions are taken. Here is the specific component code: declare var CKE ...

Learn how to easily modify a value in a CVS file by simply clicking on the data point on a highcharts graph

Is there a way to update my CSV file by clicking on a graph? I want to be able to create a graph from data in the same CSV file and then, when I click on a point, set that point to zero on the y-axis and update the corresponding value in the CSV file to 0. ...

Is it possible to delay the loading of a page using location.href?

Trying to determine when a page has finished loading using location.href. Currently, my code is set up like this and I want certain events to occur once the page is fully loaded. I attempted using $.get but encountered issues with my existing implementatio ...

What is the process for loading Syntax Highlighter on pages with pre tags?

As a Blogger, I often find myself in need of demonstrating codes on my blog. To achieve this, I have been using a Syntax Highlighter developed by Alex Gorbatchev. However, a recurring issue I face is that the files load on every single page of my blog, cau ...

Navigating the browser view across an extensive HTML page without relying on scrollbars

I have a large HTML page (approximately 7000x5000) and I need to be able to move the user's view around with JavaScript. Disabling the ability for the user to scroll by hiding the browser scrollbars using overflow:hidden on the HTML element is easy. ...

Is it possible for a chrome extension to allow only specific third-party cookies and storage to be

My Chrome extension inserts an iframe from foo.com into bar.com, creating a situation where bar.com now includes a foo.com iframe. However, I have observed that this iframe encounters difficulties when attempting to write to localStorage if the user has ...

Modifying the content inside a div element and inserting an image into it

I am facing a problem where I am unable to display the image when trying to change the inner HTML of a div by inserting an img source into it. Below is my JavaScript code snippet: var sliderimg = document.getElementById('abc_'+obj).src; $("#eve ...

What is the best way to compress JSON responses?

During a recent interview, I encountered a question that asked how to minify a JSON response. Here is the sample JSON response: { "name": "sample name", "product": "sample product", "address": "sample address" } I am unsure of how to minify this J ...