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.
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.
Comments