looking for some solutions? You are welcome.

SOLVED: How to convert string with multiple array to JavaScript object

mayursharma:

I need to convert below string to JavaScript object

const str = `[{a:b},{c:d}]
[{a:b},{c:d}]`

I am looking for object like

[[{a:b},{c:d}],[{a:b},{c:d}]]

I have tried below code

const regex = /(\n)/gm;
const str = `[{a:b},{c:d}]
[{a:b},{c:d}]`

const result = str.split(regex)
console.log(result);

getting below output

[ '[{a:b},{c:d}]', '\n', '[{a:b},{c:d}]' ]



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
Share:

No comments:

Recent