It can't be 6, because when you calculate length of a string it includes spaces too.
So,
var d = "I am a 香港人";
d.length //returns 10
d.replace(/\s+/g, "").length //returns 7, excluding spaces
FYI: Your site should be properly encoded.
I think I found what you need. "I am a 香港人" this contains a
repeated twice. So
With the help of @PSL 's answer, I found a way.
var d = "I am a 香港人";
var uniqueList=d.replace(/\s+/g, '').split('').filter(function(item,i,allItems){
return i==allItems.indexOf(item);
}).join('');
console.log(uniqueList.length); //returns 6
As you comments, I assume you sentence as "I am a 香 港 人" space between each word. Now I altered the code
var d = "I am a 香 港 人";
var uniqueList=d.split(' ').filter(function(item,i,allItems){
return i==allItems.indexOf(item);
});
console.log(uniqueList.length); //returns 6