我有一个动态生成的数组,从一个类似于这样的 XML 文档中创建:
myArray[0] = [1,The Melting Pot,A]
myArray[1] = [5,Mama's MexicanKitchen,C]
myArray[2] = [6,Wingdome,D]
myArray[3] = [7,Piroshky Piroshky,D]
myArray[4] = [4,Crab Pot,F]
myArray[5] = [2,Ipanema Grill,G]
myArray[6] = [0,Pan Africa Market,Z]
这个数组是在一个for循环里创建的,根据xml文档的不同可能包含任何东西。
我需要完成的任务是根据字母将这个数组中的项目分组,使所有包含字母 A 的数组对象被存储到另一个数组中,如下所示:
other['A'] = ['item 1', 'item 2', 'item 3'];
other['B'] = ['item 4', 'item 5'];
other['C'] = ['item 6'];
为了澄清,我需要根据数组内的变量来排序项目,例如这种情况下的字母,以便包含字母A的所有数组对象都放在新数组下的相应字母下面。
感谢任何帮助!