最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

angular - Getting 2 letter language code with javascript? - Stack Overflow

programmeradmin0浏览0评论

If navigator.language returns en-US, but I only want en because I don't care about the locale, is there a preferred way to do this? Does angular have anything built in for this or should I just split on the -?

If navigator.language returns en-US, but I only want en because I don't care about the locale, is there a preferred way to do this? Does angular have anything built in for this or should I just split on the -?

Share Improve this question asked Nov 27, 2017 at 14:36 xaisoftxaisoft 3,4518 gold badges46 silver badges78 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

use js String.prototype.slice() method.

navigator.language.slice(0,2);

This will do:

navigator.language.substring(0,2);
发布评论

评论列表(0)

  1. 暂无评论