faqts : Computers : Programming : Languages : JavaScript : Language Core : Arrays

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

30 of 36 people (83%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

How to create structured data array

May 19th, 2000 05:14
Hiroto Sekine, https://buttons.ihug.co.nz/all/mu2iafdemo.htm


function Person( name, age, sex ){
    this.name = name;
    this.age  = age;
    this.sex  = sex;
}
function makeStudentArray(){
    var i = 0;
    this[i++] = new Person( "John", 22, "male" );
    this[i++] = new Person( "Mary", 28, "female" );
    this[i++] = new Person( "Smith", 41, "male" );
    this[i  ] = null;
    this.length = i;
}
var STUDENT = new makeStudentArray();
var loop = STUDENT.length;
for (var i=0; i<loop; i++){
    if (STUDENT[i].age < 25){
        // perform something
    } else {
        // perform something
    }
}