-1

I have a need to split a string in javascript to individual components. Let me go through the example of the requirement I'm having.

This is the string I'm having:

"[InsertDelta, position: 63, lines: [return {]]"

I need to split the above string into three components as below:

InsertDela
position: 63
lines: [return {]

Is there any way to separate the strings like this in javascript?

Federico klez Culloca
  • 24,336
  • 15
  • 57
  • 93
Thiluxan
  • 131
  • 8

1 Answers1

0

You can use split to split the string at "," and then use for each to iterate through the items.

let y = "[InsertDelta, position: 63, lines: [return {]]";
let x = y.split(",");
x.forEach(item => console.log(item.replace(/\[?\]?/g, "")));
Ali Mustafa
  • 588
  • 1
  • 9