数组不会迭代值只是数组名称

时间:2015-11-25 22:21:01

标签: javascript arrays

我知道这是基本的,但我正在尝试迭代随机选择的数组的内容。此javascript返回随机数组的名称,但不列出其内容。任何帮助都会有用。

SELECT distinct StudentItem.foldername AS "foldername", 
    StudentItem.status, 
    StudentItem.vhrid, 
    StudentItem.firstname, 
    StudentItem.middleinitial, 
    StudentItem.lastname,
    dbo.getEnumDescript(StudentType, 'StudentType') AS title,
    StudentItem.email, 
    dbo.getEnumDescript(OfficeLocation, 'OfficeLocation') AS Office,
    (
        select practices.id, practices.name
        from [dbo].[StudentGroups] as aprac
        INNER JOIN [dbo].[PracticeGroups] as practices 
        on aprac.PracticeGroupID = practices.ID 
        where StudentItem.vhrid = aprac.vhrid
        FOR XML path(''), type
    ) 'StudentItem/practices/practice',
    (
        select Name schoolname, schoolYear
        from [dbo].[StudentEducation] schoolItem
        where StudentItem.vhrid = schoolItem.vhrid
        FOR XML path(''), type
    ) 'StudentItem/bio/schools/schoolItem'
FROM [dbo].[Student] as StudentItem
where StudentItem.vhrid='50330'
FOR XML path, ROOT ('StudentItem');

1 个答案:

答案 0 :(得分:3)

引用数组时不要引用数组名称。



var introOne = [
  '<img src="assets/redOne.jpg">',
  '<img src="assets/redTwo.jpg">',
  '<img src="assets/redThree.jpg">'
];

var introTwo = [
  '<img src="assets/rblueOne.jpg">',
  '<img src="assets/rblueTwo.jpg">',
  '<img src="assets/blueThree.jpg">'
];

var intros = [introOne, introTwo];

var opening = intros[Math.floor(Math.random() * intros.length)];

for (var i = 0; i < opening.length; i++) {
  document.write(opening[i]);
}
&#13;
&#13;
&#13;