更新时间:2023-12-02 23:32:04
您可以扩展 String
原型;
String.prototype.distance = function (char) {
var index = this.indexOf(char);
if (index === -1) {
alert(char + " does not appear in " + this);
} else {
alert(char + " is " + (this.length - index) + " characters from the end of the string!");
}
};
...并像这样使用它;
... and use it like this;
"Hello".distance("H");