如何设置一个等于另一个的javascript变量并使用其属性

时间:2014-04-21 03:10:21

标签: javascript arrays object properties

我只是一个初学程序员。我正在创建一个程序,用户可以从一个数组中选择对象,将其放入另一个数组中,在该数组中选择随机对象并将其作为变量。但是,我似乎无法在新数组中使用与我的新变量相同的属性。

    function verb(first,second,third,fourth,conjugation,chapter) {

    this.first = first;
    this.second = second;
    this.third = third;
    this.fourth = fourth;
    this.conjugation = conjugation;
this.chapter = chapter;
}

var family = new Array();

family[0] = new verb("amo","amare","amavi",'amatum',1,1);
family[1] = new verb("moneo","monere","monitum",2,1);
family[3] = new verb("debeo","debere","debui","debitum",2,1);


for(i=0;i<20;i++) {



    if(chap_beg< i <  chap_end) {
    var randselect  = new Array();   
     randselect.push = family[i];
     var rand = family[Math.floor(Math.random() * family.length)];   

var t = rand.third;
var perfect2 = t.substring(0,(t.length)-2);

1 个答案:

答案 0 :(得分:0)

你为什么跳过家庭[2]?这一部分应该是这样的:

randselect.push(family[i]);
var rand = family[Math.round(Math.random() * (family.length - 1))];