daily pastebin goal
70%
SHARE
TWEET

Untitled

a guest Jan 19th, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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,'\\');
RAW Paste Data
Top