Generating a two-dimensional array based on a given string

Need help converting the following array into a 2D array of strings:

[[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],[0,0,0,0,0,0,0,0,0,0,0...

Is there a way to achieve this without using additional libraries?

Answer №1

Aside from the inclusion of HTML tags, the content could easily be converted into valid JSON format. By simply removing the HTML tags and utilizing a JSON handling library such as jQuery:

var arr = $.parseJSON(theString.replace(/<br\/>/g,''));

The content could also function as standard Javascript code once stripped of the HTML tags. If you are confident in the source of the string and can guarantee it is not malicious, the eval function could even be employed to run the code:

// Warning: 'eval' is susceptible to code injection risks
var arr = eval(theString.replace(/<br\/>/g,''));

Answer №2

First step is to eliminate the <br/> tag from the given string. Once that is done, you can proceed with:

let myTwoDimensionalArray = eval(myString);

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

Alert! Server node encountered an issue while handling the response: process.nextTick(function(){throw err;});

Currently, I am working on a simple application to familiarize myself with Mongo, Express, and Node. An issue arises when I attempt to utilize res.json(docs) in the success conditional during the GET request, generating an error process.nextTick(function( ...

Display a placeholder page during the processing of an asynchronous task by Express JS

Perhaps this issue is either too simple to be overlooked or too complex to tackle, but despite my efforts of over 3 hours searching for a solution, I am unable to find one. It seems like it should be a common problem and I am just too inexperienced to loca ...

modifying the selection option depending on the previous selection made

I've attempted to find a solution for this issue on various websites and forums, but so far no one has been able to help. The problem I am facing involves a form with select options: <select name="stampa_front"> <option data-price="0"&g ...

Issue arising from background change upon component focus

My component needs to change its background color when focused, but for some reason it's not working. The hover effect works fine, but the focus doesn't. Can anyone assist me with this issue? import { CardContainer } from './styles' in ...

Opting for Mysql over MongoDB as the provider in Next.js with Next-auth

Exploring the Next.js framework for the first time, I've dived into using Next-auth to handle sign-up/login functionality based on the provided documentation. My experience so far has been smooth, especially with the MongoDB provider as recommended i ...

Difficulty intercepting emitted event from child module in Angular 4

Apologies for my inexperienced inquiry, I am attempting to trigger an event from a child component to a parent component using an @Output and EventEmitter. However, I am facing difficulties in capturing the event in my parent component. Child Component @ ...

Having Issues with JSFiddle: Difficulty with executing a basic onclick event to display a string

Having trouble with an onclick event: Simply click the button to run a function that displays "Hello World" in a paragraph element with id="demo". <button onclick="myFunction()">Click me</button> <p id="demo"></p> <script> ...

Utilize AngularJS to bind keys to arrays

Hey there, I have an array that looks like this: $scope.Selectedgroups =[183,184,24] I want to convert it to the format shown below: [{groupId:183},{groupId:184},{groupId:24}]; I've been trying to convert it using a for loop: var groups=[] ...

Sending JS variables in the data field in Laravel 8 AJAX CRUD operations

Hello, I am new to Laravel and AJAX programming and I'm attempting to transmit a JavaScript variable using the data field. Below is the code snippet I have been working on: $.ajax({ type: "post", url: ...

Navigating through Object Properties (Exploring deeply without converting to arrays)

Recently, I have been working on processing a TV guide XML file generated by tv_grab_uk_rt. I have developed a script to convert this XML into an object, allowing me to iterate through and store the data in a database. While the script is functional, I enc ...

"Struggling to make the 'overflow: hidden' property work for an absolutely positioned

I'm struggling to conceal an absolutely positioned image within a CSS grid layout. Below is the code snippet: HTML: <div class="relative-parent"> <div v-for="item in 12" class="hiding-parent"> <div c ...

Retrieve the 'message' data from the Meta-Data section of the response after sending an Ajax post request with React

After making an Ajax post request, I received the following response snippet: Data: Meta-Data: Topic : "Sign-Up" Message : "Already in the System!" Response Code : "650" . . . I'm trying to figure out how to extract and display the mes ...

How can you use a single parameter in a JavaScript function to swap the values of two numbers

Here's the challenge I'm facing: I need to create a function that will output 5 when given a(0), and 0 when given a(5). a(0) = 5 a(5) = 0 It should look like this: Hint: Use the following function structure function A(num){} something ...

Calculating the product of a 3x3 matrix and a 3x1 vector

For my project, I developed a program that prompts the user to input a 3-dimensional double vector 'v' and a 3 x 3 double matrix 'M'. The objective is for the program to output the product of 'Mv', which should ideally be a ve ...

How to Capture Clicks on Any DOM Element in React

Currently working on a web project using React and Node. My goal is to monitor all clicks across the entire document and verify if the previous click occurred within a 2-minute timeframe. ...

Using a button click to toggle the vue-ctk-date-time-picker in VueJS

Currently, I am utilizing the Vue component - https://github.com/chronotruck/vue-ctk-date-time-picker within my own component. However, I am encountering an issue where I would like to maintain the component's original functionality while having a but ...

I'm wondering why the keys in my string object for a select box are being transformed into numbers after deploying my Next.js application

Within my next.js application, I have implemented an object with string keys and string values within a select box, as shown below: export const HOURS: { [key: string]: string } = { '00': '00', '01': '01', &ap ...

Tips for efficiently utilizing both client-server side rendering and static generation rendering in web development

I am looking to implement static generation for top products using getStaticProps. Currently, there are sections in my rendering that do not require static generation, such as comments and related products. Here is the full code snippet: export default fu ...

I encounter a black screen issue while attempting to rotate a three.js cube

How can I rotate a cube around all three axes (x, y, z) using the code snippet provided below? ` <html> <head> <title>CM20219 – Coursework 2 – WebGL</title> <meta charset="utf-8"> < ...

What might be causing the sudden shifts in element positions during TweenLite animation?

I have created a demo of my code in this JSFiddle and also included it below. The issue I am facing occurs in Google Chrome, so I would recommend using that browser to replicate and fix the bug. Please note that the code is a snippet from a larger project ...