Replace a \n in objects, which are in array

I want to replace \n which is in array of objects.
For now I came across this, but it replaces only string, not an actual ‘\n’ which makes the line break.

var obj = {
  'a': '\nThe fooman poured the drinks.',
  'b': {
    'c': 'Dogs say fook, but what does the fox say?'
  }
}

console.log(JSON.parse(JSON.stringify(obj).replace(/\n/g, '')));

Thanks to everyone

>Solution :

You should use \\n in regax.

var obj = {
   'a' : '\nThe fooman poured the drinks.',
   'b' : {
      'c' : 'Dogs say fook, but what does the fox say?'
   }
}

console.log (JSON.parse(JSON.stringify(obj).replace(/\\n/g, '')));

Leave a Reply