+ 4

JS - replace with regex

I don't know why it's doing only for the first matched... How can I do to replace for all ? I did "gm" at the end of the regex but it's even not working... https://code.sololearn.com/W2OVYIss5ghQ/?ref=app

1st Aug 2018, 12:01 PM
NoxFly
NoxFly - avatar
3 odpowiedzi
+ 4
It seems like you're attempting to do with regex replace what you could do with the third optional parameter of the JSON.stringify method... Try: JSON.stringify(a,null,'\t'); ... and take a look at: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Parameters ;)
1st Aug 2018, 1:01 PM
visph
visph - avatar
+ 5
visph hinanawi thanks both !
1st Aug 2018, 1:04 PM
NoxFly
NoxFly - avatar
+ 1
what is the intended output, as i'm getting this: [ {"name":"NoxFly","age":18}, [{"name":"Max","age":17}, {"name":"Antoine","age":17}] ]
1st Aug 2018, 12:15 PM
hinanawi
hinanawi - avatar