Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第 124 期(W3C 标准-JavaScript):unicode码互转 #127

Open
wingmeng opened this issue Oct 14, 2019 · 0 comments
Open

第 124 期(W3C 标准-JavaScript):unicode码互转 #127

wingmeng opened this issue Oct 14, 2019 · 0 comments

Comments

@wingmeng
Copy link
Collaborator

// 普通字符串转 unicode
// -> "\u4f60\u597d\u4e16\u754c"
'你好世界'.split('').map(s => '\\u' + s.charCodeAt().toString(16)).join('');

// unicode 转普通字符串
String('\u4f60\u597d\u4e16\u754c');  // "你好世界"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant