Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Replace special characters in array in JavaScript

The easy way to replace special characters in an array of objects in JavaScripts
Javascript Javascript
Javascript

The easy way to replace special characters in an array of objects in JavaScript, is :

Transform the array to a json string.
Then apply a regex to replace characters.
Parse the json String to obtain a new array without the special characters.

For Exemple :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

console.log(JSON.parse(JSON.stringify(obj).replace(/[\\n\\t]/g, '')));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading