Tips on how to showcase a particular element from the final row of parsed CSV information and JSON files

Currently, I am developing a dashboard web application and utilizing Papa Parse to parse a CSV file provided by the client.

The parsing functionality is working smoothly, with data being logged in the console using a callback function.

My task now is to extract and store the values at the 10th position of the last 2 rows (note that the number of rows may vary) into two separate JavaScript variables, which will then be displayed in the HTML.

Any assistance or suggestions on how to achieve this would be greatly appreciated!

Here is the existing code snippet:

function showData(data) {
  console.log(data);
  console.log(data.item);
}

function parseData(url, callBack) {
  Papa.parse(url, {
    download: true,
    dynamicTyping: true,
    complete: function(results) {
        callBack(results.data);
    }
  });
}

Below are the array results from the parser:

22205: (105) ["c:\Users\admin\Documents\IxChariot\Tests\8ss_hk_test_udp.tst", "4ss", 4215, 4215, 17337500000, null, 3067971000, 14269529000, 82.304, 204.118, 0.385, 1946.667, null, ...]
22206: (105) ["c:\Users\admin\Documents\IxChariot\Tests\8ss_hk_test_udp.tst", "8ss", 17922, 17922, 18512800000, null, 13073661980, 5439138020, 29.38, 869.816, 0.394, 696.907, null, ...]

Answer №1

When working with your callback function, all you really need to do is extract the tenth element from each array?

function callback:(data) {
    return {
        first: data[data.length - 2][9],
        second: data[data.length - 1][9],
    }
}

To assign your variables later on, you can use a method like this:

const { first: variableOne, second: variableTwo } = callback(data)

I hope this explanation clears things up for you.

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

Modify the background of a DIV upon clicking it

Is there a way to achieve the following scenario: I have multiple DIVS <div style="background-color: black;">text1</div> <div style="background-color: black;">text2</div> <div style="background-color: bl ...

Are the Node.JS environment variables missing?

In my Node.JS application, I have set up some crucial environmental variables in the .env file, such as AUTH0_CLIENT_ID and AUTH0_CLIENT_SECRET. To enable Auth0 support on the client side, I included the following code: var jwt = require('express-jw ...

Java has the capability to tackle complex mathematical expressions with ease

Seeking guidance on a Java problem – I am new to the language and our professor assigned a Laboratory Exercise involving creating a "Scientific Calculator". This program is designed to solve expressions such as: 1. 6+(4*6) 2. ((50+25)/5)+12 3. 15/3*3 I ...

I am having trouble accessing the props testHighlight from the parent component when using the componentDidMount and componentWillReceiveProps methods

I'm brand new to working with react and I'm currently attempting to integrate react-highlight-words into my application for text searching purposes. I've set up a basic search textbox within the SearchBar.js file, while the highlighter compo ...

Forecast data from the Weather Underground API

Currently, I am utilizing the Weather Underground API to extract weather information using JSON and parsing variables. However, I have encountered an issue in my code where if I attempt to repeat the same query with a different index, the JSON data always ...

Troubleshooting Problem with MVC Ajax Requests

When working with an MVC view, I have a submit button that includes validation checks. If the validation fails, I return false to prevent the form from being submitted. In addition to standard validation, I also use an Ajax GET request to check for duplic ...

Refreshing the page to fetch dynamically updated content

I've been working on a search feature reminiscent of Google Instant using jQuery. Everything seems to be working well, but I've encountered an issue. Whenever the page is reloaded, or if a user navigates away and comes back, the search results di ...

Locate the index of an item within an array of objects based on a matching property in the

My current situation involves having an array of objects structured like this : [ {label: "<p>Opacity | %<br/></p>", customRow: false, id: 0, items: Array(13)}, {label: "Brand_hs_id", customRow: false, id: 0, items: A ...

Learn how to access different JavaScript functions from another JavaScript file within Node.js

I have a question about accessing functions from one JavaScript file to another. Specifically, I want to know how to use the function play.getQueue() in my skip.js file. I'm new to JavaScript, so I would appreciate it if you could simplify your explan ...

Following the modifications made to the JSON file using Groovy, the file now includes additional curly brackets and a "content" object within the data

Within my json file, I have the following data: {"globals":{"code":"1111","country_code":"8888","hits":80,"extra_hit":1,"keep_money":true},"time_window":{"from& ...

Creating a primary php file in Apache without the use of SQL or any database: is it possible?

Forgive me if this comes across as rude, but I'm struggling to grasp the concept of apache, PHP, and servers in general. To help myself understand better, I want to create a very basic website that assigns an ephemeral ID to each user (not a session). ...

Exploring JSON data with breeze data querying

Embarking on my first Single Page Application (SPA) journey. This SPA will serve as an HTML representation of our database structure for clients to browse through the model and run queries, without accessing the actual database content. The challenge lie ...

Learn how to display two different videos in a single HTML5 video player

Seeking a solution to play two different videos in one video element, I have found that only the first source plays. Is jQuery the answer for this problem? HTML Code: <video autoplay loop id="bbgVid"> <source src="style/mpVideos/mpv1.mp4" type ...

Templating with Underscores: Revolutionizing token markers

When using out of the box underscore templating, the default markers for raw content are <%= %>, and for HTML escaped content are <%- %>. However, it is possible to change these markers by adjusting the template settings, for example: _.templ ...

Element eradicated by mysterious force - what is the reason behind this destruction?

I encountered a peculiar issue while working on a JS game demo. For some reason, one of the functions is unexpectedly deleting the container element (even though I didn't intend for it to do so). This function usually creates another element inside th ...

"The Material UI date picker is encountering an issue with the error prop, which is being evaluated

I have developed a date picker that utilizes the Jalali calendar. While attempting to pass error checking using the error prop in the following code: <LocalizationProvider dateAdapter={AdapterJalali}> <MobileDatePicker label={lab ...

Unable to process JSON data as input for a RESTful POST request

Currently, I am developing a REST service that will receive POST calls with JSON as input parameters. Below is the pseudo code snippet I have implemented: @POST @Path("/decodeJson") //@Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_J ...

Utilizing a boolean flag to retrieve specific elements from an array

I am working with a boolean variable that determines the order of an array based on its value. Let's say I have two lists: string[] radiant_players = new string[5]; string[] dire_players = new string[5]; And a boolean variable called radiant_wins. ...

Oops! Looks like we've encountered a Scala error saying: "java.lang.Array

I'm facing an issue while attempting to generate a Row[RDD] val RowRDD = sc.textFile("InputFile.csv").map(x => x.split(" ")).map(p => Row(p(1), p(2))) The content of InputFile.csv is as follows: spark 5 1 hadoop 7 1 flink 10 1 However, upon ...

PHP Tutorial: Dynamically Adding or Removing Divs Based on Checkbox Selection

Check out this code snippet: <div id="product"> <b>SELECT PRODUCT:<br></b> <input type="checkbox" name="fruits" value="1">Orange<br> <input type="checkbox" name="fruits" value="2">Grapes<br> <input type=" ...