How can I convert string to array in JavaScript?

김영주

Here is my string.

[('hxe718a186f56f9330368d69a6f47b459427a16a17', 3), ('hx08737510fbd9eaa5182354eb826a8ce84f659ab1', 1), ('hx579250b23b1bcc809da119182bc0b8421922701f', 7), ('hx0deffb4c44da662a9b36008a5ccd3e2ef704e803', 3)]

I want to convert this string to array or JSON.

var arr = "Some works that covert string to array or JSON"

So I want to get the result like bottom.

arr[0] = > ('hxe718a186f56f9330368d69a6f47b459427a16a17', 3)

arr[1] = > ('hx08737510fbd9eaa5182354eb826a8ce84f659ab1', 1) ...

Is there any way to do this? I can't find the way.

Avanthika

Use regex - Doing a match for brackets () with /\((.*?)\)/g would be sufficient in your case.

The following snippet shows data as you expect:

const string = "[('hxe718a186f56f9330368d69a6f47b459427a16a17', 3), ('hx08737510fbd9eaa5182354eb826a8ce84f659ab1', 1), ('hx579250b23b1bcc809da119182bc0b8421922701f', 7), ('hx0deffb4c44da662a9b36008a5ccd3e2ef704e803', 3)]";
const arr = string.match(/\((.*?)\)/g);
console.log(arr);
console.log(arr[0]);
console.log(arr[1]);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I convert string to array of objects in JavaScript

How can I convert a String to a char array?

How can I convert an array to string in swift?

How can I convert string to a array?

How can I convert a string to boolean in JavaScript?

How can I convert a string to object in Javascript?

how can i convert object into an array in javascript?

How I can convert array to object in Javascript

How can I create a function to convert the string "ABCD" to an array like: ["A", "AB", "ABC", "ABCD"] in Javascript?

How we can convert an string of array to Array in JavaScript?

How can I use Lambda to convert a String array to Integer array?

How can I convert an Int array into a String? array in Swift

How can I convert an array of string arrays into an array of objects?

How can i convert json array in string format into array[]

How can I convert an array of objects to array with a unique id in javascript?

How can I convert an array into a comma separated string?

How can I convert my circular array into a String?

How can i convert an array in Json string to c# object?

How can I convert CharArray / Array<Char> to a String?

How can I convert a json string to a json array using Newtonsoft?

How can I convert a comma-separated string to an array?

How can I convert a hex string to a byte array?

How can I convert a zero-terminated byte array to string?

How can I convert a string to JSON and save the data in an array?

How can I convert String into array of characters in java

How can I convert array to string in hive sql?

How can I convert a string of numbers to an array or vector of integers in Rust?

In Perl, how can I convert an array of bytes to a Unicode string?

How can I convert multi-line string to objects or an array?