Why are the values in a JavaScript nested array not accessible?

I am currently developing a Telegram application for a gaming project. The process involves multiple steps: Step1 requires me to call the MYSQL database to fetch data in lua. Step2 involves sending the table data to my NUI in the telegram.js file. Step3 is focused on converting the string into an array.

The structure of the data being pulled is perfectly represented in my telegram.js file:

  var Atest = [
    (a1 = [7, 1, 'This is a test', 1, '05:30:35pm', '09/23/2021', 1]),
    (b1 = [7, 1, 'Test Test', 1, '05:40:35pm', '09/26/2021', 2]),
  ];

While this setup works well within the .js file, encountering issues arise when trying to extract data from a string received from the telegram.lua file and convert it into an array.

for (const [key, value] of Object.entries(Atest)) {
      console.log(`${key}: ${value}`);
    }
0: 7, 1, This is a test, 1, 05:30:35pm, 09/23/2021, 1
1: "diff string ect..."

A particular challenge faced is accessing the inner values when processing the string. While the provided example functions correctly due to its location in the .js file, extracting data from a string fails to register inner arrays using index references.

Even utilizing for k,v in pair do does not yield accurate results, particularly when maintaining the order of elements. An efficient solution would involve converting the string into a complete array structure.

The code snippet essential for my menu program is detailed below:

telegram.js

function newMessages(nTT) {
    for (const [key, value] of Object.entries(nTT)) {
      console.log(`${key}: ${value}`);
    }
    sleep(100);
    console.log(nTT);
    for (const [k, v] of nTT.entries()) {
      var split_date = v[5].split('/');
      var newb = document.createElement('a');
      var newb_i = document.createElement('input');
      // rest of the code block...
    }
    check_checked();
    disable_tele_input();
  }

Inevitably, modifying the data structure to use id values instead of numerical indices when iterating through it will be necessary. Such adjustments should facilitate smoother integration with existing database records and Lua strings.

Despite investing significant time attempting various approaches like arr.push, split(), or RegExp matching to reconstruct the string inside JavaScript as an array, the desired outcome remains elusive. Assistance in resolving this predicament is highly appreciated.

The actual dataset extracted from the MySQL database is as follows:

MSYQL DB

// Data entries...

This represents the Lua script snippet handling the sorting:

telegram_sv.lua

// Lua scripting logic...
telegram.js

// Further JavaScript functionality...

Your assistance and guidance are greatly appreciated!

¯\_(ツ)_/¯

Answer №1

After realizing my error, I corrected it by adding JSON.parse() to the code.

newTT = [];
   for ([k, v] of Object.entries(nTT)) {
    newTT.push(JSON.parse(v))
   }

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

Attain the ability to distinguish errors in Promises

Context In my project, I have implemented a REST API that interacts with MongoDB using Node.js and Express. The issue at hand involves handling errors based on different scenarios when making requests to the NoSQL database. Challenge The current impleme ...

Refreshing data and manipulating arrays using AngularJS

Currently, I am developing an application utilizing AngularJS and LocalStorage. I've encountered a challenge that seems a bit too intricate for me to handle. The app involves managing lists of people with the ability to add arrays of names. The proce ...

What is the reasoning behind npm modules such as material-ui exporting both es6 and es5 files?

When installing several npm modules, such as @material-ui/core, I noticed that there are three different ways to import the same React component: import { AppBar } from '@material-ui/core' import AppBar from '@material-ui/core/AppBar/AppBar ...

Issues with JavaScript and CSS functionality not functioning correctly as expected

There seems to be an issue with the order of HTML elements in the following code. When I place the div with the class thumb-bar before the full-img div, the JavaScript functions correctly. However, if I switch their positions, the JavaScript functionalitie ...

Refresh the value of a JavaScript variable on the server using a script executed on the client side

Hello, I'm working on a webpage that utilizes JavaScript to find the location of my device. I am interested in updating the variables within the JavaScript code from a script that runs on my laptop. Is this even possible? Below is the code snippet: i ...

When using jQuery, the content loaded with the $ajax function only displays after refreshing the page

Located on an external server is a directory containing various .html files, including one named index.html. The server has the ability to load either the folder name or foldername/index.html in its URL. Each html file within the directory loads a corresp ...

console fails to return a function even when it is defined

After clicking the "stopCrash" button, I want the function backAgain to be executed 2 seconds later. However, I am encountering an error in the console: Uncaught TypeError: this.backAgain is not a function. Do you have any suggestions on how to fix this i ...

Troubleshooting jQuery compatibility issues with Wordpress

Having some trouble implementing zclip on my Wordpress site to copy dynamically generated text. The code works fine as a standalone html page with embedded jquery, but it's not translating well to my Wordpress site. Even though I've placed the co ...

The footer section of my website seems to have gone missing in the HTML/CSS coding

I'm having trouble with my website footer not displaying. I've tried using "position: absolute; top: 50px; left:100px;" in my HTML/CSS, but it's not working. Can anyone help me fix this issue? Here is a link to the code I'm working on: ...

Encountered a $resource configuration issue while making a request to the SharePoint REST service with Angular

In an old sample app without angularJS, a rest service is called in the following way: This app does not use angularJS. var listName = "Events"; // the url to use for the REST call. var url = SPAppWebUrl + "/_api/SP.AppContextSite(@target ...

"Ionic offers a seamless integration of both side menu and tabs for enhanced navigation

I am working on implementing a sidemenu and tabs on the same screen in my Ionic app project. Currently, it is almost working, but I need the bottom tabs to be visible at all times while also being able to navigate to other views from the sidemenu without ...

Rearranging information within a JSON structure

Here is a sample of Javascript object and code to consider: Javascript Object { "thing":{ "data":"some data", "thumb":"some data", "data1":"some data", "data2":"some data", "data3":"some data", }, "extra1":[ ...

The JSON.stringify() method does not update the object that has been modified by an event

Below is the code snippet: //function triggered when columns are reordered dataTable.on('column-reorder', function (e, settings, details) { var userData = tableWidget.grid('userData'); console.log(userData); //userData object s ...

Validation does not occur once the data has been loaded

I developed a function that calculates the percentage of form completion. However, I am encountering an issue where when editing an existing record, the validation does not kick in until data is edited in one of the inputs. <div ng-form="dtform" class ...

show an HTML webpage within a <div> container using AJAX technology

I am trying to include an HTML page named Introduction.html (located in the same folder as x.html) within div1. However, it does not seem to be loading properly. Below is a snippet of the code from x.html x.html <!DOCTYPE html> <h ...

Unable to pass data from function to array in Swift 3 is a problem I am currently facing

I'm able to retrieve the JSON data, but I'm having trouble adding it to the abcArr array. When I check the count of abcArr in the viewDidLoad() method, it shows as 0. Below is the code snippet I'm working with: Thank you in advance for any ...

Create random animations with the click of a button using Vue.js

I have three different lottie player json animation files - congratulations1.json, congratulations2.json and congratulations3.json. Each animation file is configured as follows: congratulations1: <lottie-player v-if="showPlayer1" ...

Received an error while attempting to install react-router-dom

I keep encountering this error message whenever I try to install react-router-dom using NPM in VS Code: https://i.sstatic.net/hFshb.png npm ERR! Unexpected end of JSON input while parsing near '...stack-launcher":"^1.0' npm ERR! You can find ...

Leveraging a specific section of an HTML5 CSS3 Bootstrap template in a separate template

As I create my website using a combination of free templates, I often find myself needing to merge elements from different designs. One specific example is wanting to incorporate the "Client Logo Slider" component from template 2 into my original template. ...

Double array summation function

It is necessary for me to calculate the total coursePrice from this JSON data source here using AngularJS (javascript). I need to calculate two sums: one for each school and another for all schools combined. I have already displayed all the data in a tabl ...