Attempting to generate a JavaScript array with the intention of converting it to a JSON format

Looking for some assistance here. I have a function that returns the following JSON.stringify output in JavaScript:

{"tablerows":[{"colone":"test","colthree:":"testf","row:0},{"colone":"testd","row":1}]}

However, I am aiming to achieve a structure with an additional level for each row, like this:


row0


row0.colone: test


row0.colthree: testf


row1


row1.colone: testd

for (var i = 0; i < rowCount; i++) {
var row = table.rows[i];
var currentrowcellcount = $('td', row).length;

if (currentrowcellcount == 4) {
var colone = row.cells[0].childNodes[0].childNodes [0].innerHTML;
var coltwo = row.cells[1].childNodes[0].childNodes[0].innerHTML;
var colthree = row.cells[2].childNodes[0].childNodes[0].innerHTML;
tablerow = {
'colone': colone,
'coltwo': coltwo,
'colthree': colthree
}
container.tablerows.push(tablerow);
container.tablerows[i].row = i;
}
else if (currentrowcellcount == 2) {
var fieldnameone = row.cells[0].childNodes[0].childNodes[0].innerHTML;
}
}
$('#SuccessUpdate').fadeIn(500).delay(500).fadeOut(500);
alert(JSON.stringify(container));

Answer №1

This question lacks the quotation marks. I have extracted the values from the JSON below:

let data = {"rows":[{"name":"Alice","age":25,"row":0},{"name":"Bob","row":1}]};

console.log(data.rows[0].name); 
console.log(data.rows[1].age); 

Check out the jsfiddle: http://jsfiddle.net/5b4608b9/

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

Error encountered in Firefox: THREE.js throws a TypeError because 'global' is undefined

After attempting to integrate three.js into my code as a standalone script without using webpack, browserify or requirejs, I encountered an issue. My setup involves loading an external Angular app and extending it, but now I need my own version of THREE.js ...

Loop through the component name and route path in ReactJs to efficiently organize and structure your application

In my route file coding for ASP.NET, I am creating routes by fetching details from the backend. Successfully getting details like [Contacts, Pipelines, Stages]. import * as React from 'react'; import { BrowserRouter, Redirect, Route } from &apos ...

Tips for creating a page that submits itself

Currently working on a PHP script that will automatically submit an ID to itself and trigger an auto refresh to send data to the updated page. Is it feasible to use the meta refresh tag for this purpose? ...

GWT error: empty stack

Every time I attempt to perform an operation, I encounter this exception. (TypeError): b.k.g.E is null stack: TBe([object Object]) .... What steps can I take to fix this error? ...

One way to create a unique JavaScript Module Pattern that retrieves the default value of a

I'm struggling to retrieve the latest private property from a Module, as I keep getting the initial value instead of the most recent one. Upon submission of the form and triggering onSuccess, I assign partnerId = 10. Subsequently, upon clicking an e ...

Is there a way to obtain the URL before the page finishes loading, even if the specified waiting time for the webdriver has expired?

Currently, I am attempting to retrieve the URL even if the page is still in the process of loading. However, my goal is to only obtain the URL after a specified wait time of 10 seconds has passed and then trigger a custom exception. I have experimented w ...

Are you receiving a response code 500 when making a request to a presigned URL?

I've been encountering an issue with generating presigned URLs for files from my S3 bucket. Although I can successfully read files and obtain a list of file contents, when attempting to create a presigned URL using the following code snippet: reports ...

The Bootstrap Modal consistently shows the contents of the first record when used within a SQL While Statement

As a newcomer, I am in the process of converting an operational Bootstrap modal that houses a post form. Initially, the modal would open using a button with a specific Id and would always display the FORM contents from the first record found in the SQL w ...

Having trouble getting "Hello World" to display in ReactJS

I can't seem to get "hello world" as the output in my code. It's a simple code, but I'm getting a different result when using the createElement function. I'm still new to react and could use some help. Here is the code: <!DOCTYPE h ...

Instructions on activating dark mode with the darkreader plugin on a Vue.js website

Is there a way to implement DarkMode in a Vue.js application? I attempted to integrate darkmode using this npm package, but I kept encountering the error message: DarkMode not defined. ...

Ways to Adjust the Earth's Position in WebGL Earth

I have been working with this WebGL Earth component for my project, but I am facing difficulty in adjusting the position of the planet on the canvas. My intention was to place the planet at the bottom of the page, but I haven't been able to achieve th ...

How can mouse clicks be detected using jQuery?

I am looking to dynamically add a class to a link as soon as the user clicks on it, rather than waiting for the mouse click event to be released. Additionally, I want this added class to be removed once the user releases the mouse click. My goal is to repl ...

What is causing the failure of this variable assignment in the NodeJS REPL?

Could anyone provide some insight on the behavior I am experiencing? I assumed that since I can set the global variable f from within this callback, I should also be able to change it. However, my understanding of how node handles context versus global in ...

Show or conceal a child component within a React application

In my React render function, I am working with the following code: <div> <InnerBox> <div>Box 1</div> <HiddenBox /> </InnerBox> <InnerBox> <div>Box 2</div> & ...

Reading values from a properties file using HTML

Here's a snippet of my HTML code: First name: <input type = "text" > Last name: <input type = "text"> Instead of manually inputting the field values (First name, Last name) in the HTML, I am interested in reading them ...

Develop an Android application that utilizes the Wordpress API and GSON for seamless integration and

Looking to develop an Android native app for my Wordpress blog. I've heard about Wordpress's JSON-API for managing blog information, but not sure how to utilize it. Can someone provide a brief overview of its usage and whether GSON library can be ...

The concept of circular dependencies in ES6 JavaScript regarding require statements

After transferring a significant amount of data onto the UI and representing them as classes, I encountered some challenges with managing references between these classes. To prevent confusing pointers, I decided to limit references to the data classes to ...

Tips for retrieving the first true value in an *ngIf statement within an *ngFor loop

I have an array of items that must be shown based on different roles. I am looking for the first item in the array that meets the ngIf condition. Below is my code snippet: This is how my Array initially looks: parentTabList = [ { nam ...

Browsing a JSON file sequentially

My JSON file contains key-value pairs, where each value is a list of items: { "car":["BMW", "AUDI"], "OS":["Mac", "Win", "Ubuntu"], "food":["Burger", "Taco"] } I am looking to parse this data in a Java class and convert it into an ordere ...

Problem with AngularJS Multiselect checkbox dropdown configuration

In my application, I have a pop-up that includes a multi-select dropdown menu. Here is the code for the Multi-Select Dropdown: <select name="edit_tags" class="form-control" id="advisor_article_tagsx" multiple="" required ng-model="article_selected ...