Guest User

Untitled

a guest
Jan 19th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. function convertToUnicode(str) {
  2. return str.replace(/[\u0080-\uffff]+/g, function (match) {
  3. return escape(match).replace(/%u/g, "\\u");
  4. }).toLowerCase();
  5. }
  6. let obj = {
  7. a: convertToUnicode('あ');
  8. b: convertToUnicode('い');
  9. c: convertToUnicode('う');
  10. }
  11. // JSON.stringify add escape "\". So, replace the escape.
  12. let str = JSON.stringify(obj).replace(/\\\\/g,'\\');
Add Comment
Please, Sign In to add comment