Getting 2 letter language code with javascript?

Viewed 2448

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 -?

2 Answers

use js String.prototype.slice() method.

navigator.language.slice(0,2);

This will do:

navigator.language.substring(0,2);
Related