-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
  • 26,308
  • 17
  • 56
  • 95
Thiluxan
  • 177
  • 4
  • 13

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
  • 676
  • 3
  • 14