数组中的拼接数组

问题描述 投票:0回答:1

我如何在另一个数组中拼接一个数组?

我正在尝试为班上的孩子们制作游戏。某种琐事历史问题的创建者。如何拼接MasterArray,以使我摆脱allEnglandArray中的子阵列(Hard-England和Medium-England)。因为“ MasterArray.splice()”似乎会受到影响-仅拼接allEngland数组或allFrance数组。但是我需要摆脱那些子数组...

我的代码:

var Easy-England:Array = ["item1","item2","item3","item4","item5"];
var Medium-England:Array = ["item6","item7","item8"];
var Hard-England:Array = ["item9","item10"];
var allEngland:Array = [Easy-England,Medium-England,Hard-England];

var Easy-France:Array = ["item11","item12","item13","item14","item15"];
var Medium-France:Array = ["item16","item17","item18"];
var Hard-France:Array = ["item19","item20"];
var allFrance:Array = [Easy-France,Medium-France,Hard-France];


// the list of countries goes on and on and on... (Italy, Hungary, etc.)


var allStuff:Array = [allEngland, allFrance, etc.];
var MasterArray:Array;

// FUNCTIONS

// clear MasterArray - first I clear out completely the MasterArray

function clearMasterArray():void
{
    MasterArray.splice(0);
}

// update MasterArray - than I fill the MasterArray with data according to checkBoxes

function updateMasterArray():void
{
    for (var i:int = 0; i<checkBoxBlock.myCheckBoxes.length; i++)
    {
        if (checkBoxBlock.myCheckBoxes[i].selected)
        {
            MasterArray.push(allStuff[i]);
        }
    }
}    


// splice MasterArray - last thing I do is splice the items according to student's proficiency level, referred to as "studentPL".

function spliceMasterArray():void
{
    if (studentPL == 1)
    {
        for (var i:int = 0; i<allStuff.length; i++)
        {
            allStuff[i].splice(5,5);
        }

    }

    if (studentPL == 2)
    {
         for (var i:int = 0; i<allStuff.length; i++)
         {
            allStuff[i].splice(8,2);
         }

    }

    if (studentPL == 3)
    {
        for (var i:int = 0; i<allStuff.length; i++)
        {
            trace("no need to splice");
        }
    }
 }

此后,我按此顺序在另一个函数中调用这些函数...

function creatorFunction():void
{
    clearMasterArray();
    updateMasterArray();
    spliceMasterArray();
}
arrays actionscript-3
1个回答
0
投票

而不是:

var allEngland:Array = [Easy-England,Medium-England,Hard-England];

尝试一下:

var allEngland:Array = Easy-England.concat(Medium-England, Hard-England);

这样,您将拥有一个'flat'数组(没有子数组),因此更易于处理。

© www.soinside.com 2019 - 2024. All rights reserved.