Tutorial, Built in Objects

Introduction

String

Methods

match

This method is used to match a specifed regular expression against a string. If one or more matches are made, an array is returned that contains all of the matches. Each entry in the array is a copy of a string that contains a match. If no match is made, a null is returned.

This method is similar to indexOf() and lastIndexOf(), but it returns the specified string, instead of the position of the string.

Note: The match() method is case sensitive!

myString = new String("DevGuru.com")
myRE = new RegExp("guru", "i")

results = myString.match(myRE)
for(var i =0; i < results.length; i++){
    document.write(results[i]);
}
Guru

replace

The replace() method is used to replace some characters with some other characters in a string.

var str = "Visit Microsoft!";
document.write(str.replace(/microsoft/i, "W3Schools"));

Parameter

Description

findstring

Specifies a string value to find. To perform a global search add g flag to this parameter and to perform a case-insensitive search add an i flag.

newstring

Specifies the string to replace the found value from findstring.

Note: The replace() method is case sensitive.

Code Snippets

Trim function, Code Snippets

Date

We define a Date object with the new keyword.

var myDate=new Date()

Array

Define

We define an Array object with the new keyword. The following code line defines an Array object called myArray:

var myArray=new Array()

There are two ways of adding values to an array (you can add as many values as you need to define as many variables you require).

var mycars=new Array()
mycars[0] = "Saab"
mycars[1] = "Volvo"
mycars[2] = "BMW"
var mycars=new Array("Saab","Volvo","BMW")

You could also pass an integer argument to control the array’s size:

var mycars=new Array(3)
mycars[0] = "Saab"
mycars[1] = "Volvo"
mycars[2] = "BMW"

Accessing

document.write(mycars[0])

Array Object Reference http://www.w3schools.com/jsref/jsref_obj_array.asp

Boolean

We define a Boolean object with the new keyword.

var myBoolean = new Boolean()

All the following lines of code create Boolean objects with an initial value of false:

var myBoolean=new Boolean()
var myBoolean=new Boolean(0)
var myBoolean=new Boolean(null)
var myBoolean=new Boolean("")
var myBoolean=new Boolean(false)
var myBoolean=new Boolean(NaN)

Boolean Object Reference: http://www.w3schools.com/jsref/jsref_obj_boolean.asp

Math Object

HTML DOM Objects

window

Browser Detection

Cookies

Form Validation

Animation

Image Maps

Timing Events