我有两个不同的数组,名称和分数,我想将它们放在同一数组中,以便其[名称:,分数:]。
var allNames:Array = ["Test A", "Test B", "Test C"];
var allScores:Array = ["10","7","0"];**
例如,它将每个数组的第一个元素放在一起,然后将第二个和第三个元素放在一起。所以上面的数组变成
var NamesAndScore = [names:Test A score:10], [name:Test B score:7], [name:Test C score:0]
因为我是初学者,如果这看起来很傻,我很抱歉。
var allNames:Array = ["Test A", "Test B", "Test C"];
var allScores:Array = ["10","7","0"];
// Initialise a new array for the names and scores
var namesAndScores:Array = [];
for (var i:int = 0; i < allNames.length; i ++)
{
// Push an object with name and score properties onto the new array
namesAndScores.push({
name: allNames[i],
score: parseInt(allScores[i], 10)
});
}
// To access the name and score properties of the first element of the new array
trace("name 1", namesAndScores[0].name, "score 1", namesAndScores[0].score);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句