switch between cameras in javascript?

how do you switch between cameras in javascript? I've tried

gameObject.Find("cam1").GetComponent("Camera").active = true/false

but it's not working, an error comes up that says "NullReferenceExeption"

so is there any other way?

i would use something like this :

var cam1 : Camera;
var cam2 : Camera;

function Update () {
     if(Input.GetKeyDown("1")){
          cam1.enabled = true;
          cam2.enabled = false;
     }
     if(Input.GetKeyDown("2")){
          cam1.enabled = false;
          cam2.enabled = true;
     }
}

The Null reference exception is coming up because Unity cannot find a GameObject with name - "cam1". Instead you can try using an If condition to check if the GameObject exists and then change the settings.

I think the code should be something like this -

function Start() 
{
if(GameObject.Find("cam1"))
camera1 = GameObject.Find("cam1");
camera1.Camera.enabled = false/true;
}