Guide on parsing an Array of arrays using JSON.parse

I have received a JSON.stringified Array of arrays in a variable named request.

alert(request);

When I alert the above, I get the following message:

"[[\"0\",\"MahaShivRatri\"],[\"0\",\"A Night with the Divine\"],[\"0\",\"Attend In-Person\"],[\"0\",\"11 March 2021\"],[\"0\",\"6 PM to 6 AM IST\"],[\"0\",\"Attend Mahashivratri celebrations with Sadhguru in the presence of Adiyogi at the Isha Yoga Center\"],............

Next, I try to parse this JSON string:

var arr = JSON.parse(request);
alert(arr);

When I alert a specific element of this Array:

alert(arr[0][1]);

The alert box shows undefined.

How can I properly extract an Array of arrays from a JSON.stringified Array of arrays?

Thank you.


Edits

1. The original full stringified request is this :

console.log(request);

logs this

"The full stringified request"

2. When I parse it and then log it:

var arr = JSON.parse(request); console.log(arr);

This gets logged:

"The parsed array"

3. finally

console.log(arr[0]);

logs just this:

[

Answer №1

Assuming the ............ at the conclusion of the string within the result variable is merely a placeholder for additional data that has not been included, the code you have provided seems to be functioning correctly (as shown below):

const request = "[[\"0\",\"MahaShivRatri\"],[\"0\",\"A Night with the Divine\"],[\"0\",\"Attend In-Person\"],[\"0\",\"11 March 2021\"],[\"0\",\"6 PM to 6 AM IST\"],[\"0\",\"Attend Mahashivratri celebrations with Sadhguru in the presence of Adiyogi at the Isha Yoga Center\"]]";
const arr = JSON.parse(request);
console.log(arr[0][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

What is the method for viewing the content within div tags on an apex page?

Locationbox is a system outside of Salesforce, similar to Google Maps. An example can be viewed here; I am aiming to integrate it into the Salesforce platform. The first script tag fetches JavaScript code from the Locationbox service. Once the startup() f ...

Changing a portion of a string into a java.util.Date

After posting DateTime as JSON, it gets transformed into "/Date(1512839439513)/" I am looking to simply convert this format to java.util.Date "/Date(1512839439513)/" needs to be converted to java.util.Date My attempt so far: String date = finalObject.g ...

Conditions for JQuery Ajax handlingIs there anything specific you would

I am looking to implement a try-catch scenario in Laravel where, if successful, a certain message will appear and if it fails, a different message will be displayed. However, when executed successfully, it seems to display the second message instead. $.a ...

Is it possible to send an array through an ajax URL?

Is it possible to pass a PHP array as a URL parameter using the GET method? My PHP array looks like this: Array ( [0] => 4 [1] => 5 ) To achieve this, I first convert it into an AngularJS array by doing the following: $scope.myData.excludeList = &a ...

Leveraging ThemeProvider Parameters with Global Styled-Components

When working with styled-components, how can I access the props of the ThemeProvider in the context of global.js? For instance, in my theme.js file, I have ${props => props.theme.fonts.fontSize} set to a default font size of 16px. const theme = { ...

What is the process for submitting data using AJAX in Django?

I am facing an issue with my dynamically updating form. When I submit the form, I want to post the data to a views function and receive a response. Below is the code from my template file: $("#myForm").submit(function(){ event.preventDefault(); va ...

Creating a JSON object from an array of data using TypeScript

This might not be the most popular question, but I'm asking for educational purposes... Here is my current setup: data = {COLUMN1: "DATA1", COLUMN2: "DATA2", COLUMN3: "DATA3", ..., COLUMNn: "DATAn"}; keyColumns = ["COLUMN2", "COLUMN5", "COLUMN9"]; ...

Merging two individual JavaScript scripts to ensure seamless functionality for both

I am facing a challenge with utilizing two scripts simultaneously: Script 1: $(document).ready(function () { $(".tabContent").not(":first").hide(); $("ul.tabs li:first").addClass("active").show(); $("ul.tabs li").click(function () { $ ...

Dealing with Redis session management in the event of a database disconnection

Having trouble with losing connection to Redis, which is used for sessions in my Express App. var RedisStore = require('connect-redis')(express); sessionStore = new RedisStore(config.db.redis.connection); sessionStore.client.on('error' ...

Another problem with CORS again?

My rails application uses the host http://myhost.dev to search for music through the vk.com API. The API provides a search method called audio.search. Below is the code snippet from my search.js.erb file which is executed via a remote link to the search ac ...

Styling a nested scrollbar using JQuery

I am looking to customize two scrollbars using a jquery plugin or JS library. Here is the HTML code: <div id="container"> <div class="fixedHeightContainer"> <div class="fixedHeightContent"> Lorem ipsum dolor sit amet, con ...

Inject data from ajax into the body of the html document

Is it possible to retrieve values from an ajax call and insert them into the body of an HTML document? Here is an example: function check() { $.ajax({ url : '/check', datatype : 'json', async ...

Tips for using the arrow keys to navigate the cursor/caret within an input field

I am trying to create a function that allows the cursor/caret to move inside an input field character by character using the arrow keys (ArrowLeft, ArrowRight) on a keydown event. Current Approach: const handleKeyDown = (e: KeyboardEvent<HTMLInputEle ...

Utilizing AJAX with a combination of JSON and HTML data types

I recently completed a tutorial on ajax and implemented a script that retrieves JSON data and appends it to a table. $.ajax({ url: 'insert.php', type: 'POST', data: {data1: name, data2: phone, data3: address}, dataTyp ...

Achieving a single anchor link to smoothly scroll to two distinct sections within a single page using React

There is a sidebar section alongside a content section. The sidebar contains anchor links that, when clicked, make the corresponding content scroll to the top on the right-hand side. However, I also want the sidebar link that was clicked to scroll to the ...

A method for merging the values of three text fields and submitting them to a hidden text field

<label class="textRight label95 select205">Cost Center: </label> <input type="hidden" name="label_0" value="Cost Center" /> <input type="text" name="value_0" class="input64 inputTxtGray" value="" maxlength="10" /> <input type=" ...

When incorporating axios within an express route, it is causing the data field to display unusual characters instead of JSON

I've been grappling with this issue for quite some time now, and any assistance would be greatly appreciated. Initially, I attempted to resolve the problem by utilizing the Moralis nodeJs library. While it worked fine on my local environment, it retu ...

Invoking a JavaScript function within a different JavaScript function

Is there a way to ensure that the JavaScript function works properly even when using a text editor? var editor = $('#CKEditor1').ckeditorGet(); editor.on("instanceReady", function () { this.document.on("keydown", function (event) { ...

The JSON parsing encountered an error: Domain=NSCocoaErrorDomain Code=3840 "Failed to complete the operation. (Cocoa error 3840.)"

Currently, I am using the sendAsynchronousRequest request method to communicate with the server and retrieve data from it. Oddly enough, when I test the web service in a browser, everything seems to be functioning correctly and I receive the expected respo ...

Navigating through various product categories in Angular's routing system

Greetings! I am currently building a Shop Page in Angular 4 and encountering an obstacle with Angular routing. The issue arises when a user clicks on a product category, the intention is for the website to direct them to the shop page. On the homepage, th ...