คุณสมบัติส่วนกลางเป็นคุณสมบัติบูลีนแบบอ่านอย่างเดียวของวัตถุ RegExp ระบุว่านิพจน์ทั่วไปหนึ่งๆ ทำการจับคู่ทั่วโลกหรือไม่ กล่าวคือ สร้างด้วยแอตทริบิวต์ "g" หรือไม่
ตัวอย่าง
คุณสามารถลองเรียกใช้รหัสต่อไปนี้เพื่อเรียนรู้วิธีการทำงานกับคุณสมบัติ RegExp ส่วนกลาง
<html>
<head>
<title>JavaScript RegExp global Property</title>
</head>
<body>
<script>
var re = new RegExp( "string" );
if ( re.global ){
document.write("Test1 - Global property is set");
} else {
document.write("Test1 - Global property is not set");
}
re = new RegExp( "string", "g" );
if ( re.global ){
document.write("<br />Test2 - Global property is set");
} else {
document.write("<br />Test2 - Global property is not set");
}
</script>
</body>
</html>