Friday, June 22, 2012

length

Properti String.length mengembalikan banyaknya karakter di dalam string, termasuk whitespace.

Sintaks:

stringObj.length

String.length adalah properti standard JavaScript 1.0+, JScript 1.0+, ECMAScript 1.0+ dan di dukung Google Chrome Beta+, Firefox 1.0 (Gecko 1.7)+, IE 3+, Netscape Navigator 2.0+, Opera 3.0+, Safari 1.0+.

Contoh 1:

var stringObj = new String("ABC"); document.write(stringObj.length); // 3

Contoh 2:

var stringObj = new String("A B C"); document.write(stringObj.length); // 5

Contoh 3:

var stringObj = new String("\"ABC\""); document.write(stringObj.length); // 5