Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's wrong with this javascript? Array not defined

What's wrong with this code?

var divarray = document.getElementById("yui-main").getElementsByTagName("div");
var articleHTML = array();
var absHTML;
var keyHTML;
var bodyHTML = array();
var i = 0;
for ( var j in divarray) {
    if(divarray[i].className == "articleBody"){
  alert("found");
  articleHTML = divarray[i];
  break;
 }
 bodyHTML[i] = '';
 if(articleHTML[i].className == "issueMiniFeature"){continue;}
 if(articleHTML[i].className == "abstract"){absHTML = articleHTML[i]; continue;}
 if(articleHTML[i].className == "journalKeywords"){keyHTML = articleHTML[i]; continue;}
 bodyHTML[i] = articleHTML[i];
 i++;
}

This is the error I am getting:

ReferenceError: array is not defined

I am using Google Chrome if it helps any.

like image 581
Arlen Beiler Avatar asked May 18 '10 19:05

Arlen Beiler


4 Answers

Note! Javascript IS case sensitive you have to use upper-case A in word Array.

var myarr = new array(); //THIS IS WRONG! and will result in error not defined

So these are the correct ways:

var myarr = new Array(); //THIS IS CORRECT (note the "big" A) :)
var myarr = []; //and this is correct too
like image 103
jave.web Avatar answered Sep 18 '22 15:09

jave.web


It's not php - you should use

var variable_name = new Array()

or even better

var variable_name = []
like image 37
Andris Avatar answered Sep 19 '22 15:09

Andris


You first need to define

var divarray = new Array(); 
like image 42
Pinu Avatar answered Sep 19 '22 15:09

Pinu


var articleHTML = new Array();
like image 38
derek Avatar answered Sep 19 '22 15:09

derek