-3

I need to convert raw String to json array in javascript below the my logic

Original:

"[template1,template2]";

Exception:

"["template1","template2"]";
1
  • 4
    Did you try out something? If yes, please post that code Commented Jul 22, 2019 at 12:35

1 Answer 1

1

use slice to retrieve the text between the square brackets and then use split.

const input = "[template1,template2]";

const arr = input.slice(1, -1).split(',');
console.log(arr);

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.