English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript String prototype properties

 JavaScript String Object

prototypeProperties allow you to add properties and methods to the String object.

Note:Prototype is a global property that is available for almost all objects (Number, Array, String, and Date, etc.).

Syntax:

String.prototype.name = value

Create a new string method that returns the number of vowels in the given text:

String.prototype.countVowels = function() {
var x = this.match(/[aeiou]/gi);
return  (x === null ? 0 : x.length);
};

Using new methods on strings:

var str = 'Hello world';
str.countVowels();  // return 3

Test and see‹/›

Browser Compatibility

All browsers fully support the prototype property:

Properties
prototypeYesYesYesYesYes

 JavaScript String Object