如何保持数组的原始顺序?

时间:2019-05-23 10:16:43

标签: arrays typescript sorting

我有一个数组,键的值是这样的

let reorderstructure = []; 
    reorderstructure['_id'] = structure['_id'];
    reorderstructure['status'] = structure['status'];
    reorderstructure['time'] = structure['time'];
    reorderstructure['status'] = structure['status'];
    reorderstructure['location'] = structure['location'];
    reorderstructure['location-relative'] = structure['location-relative'];
    reorderstructure['rd-section'] = structure['rd-section'];
    reorderstructure['location-note'] = structure['location-note'];
    reorderstructure['location-latlng'] = structure['location-latlng'];
    reorderstructure['perpetrator'] = structure['perpetrator'];
    reorderstructure['act'] = structure['act'];
    reorderstructure['means'] = structure['means'];
    reorderstructure['narrative'] = structure['narrative'];
    reorderstructure['victim'] = structure['victim'];
    reorderstructure['ngo-incident'] = structure['ngo-incident'];
    reorderstructure['private-note'] = structure['private-note'];

但是,当尝试输出 reorderstructure 时,它将输出为

original array

我希望重新排序结构遵循我最初的意图,而不要按升序排序。

我试图做

    reorderstructure.push({'_id': structure['_id']});
    reorderstructure.push({'status': structure['status']});
    reorderstructure.push({'time': structure['time']});
    reorderstructure.push({'status': structure['status']});
    reorderstructure.push({'location': structure['location']});

这将输出我喜欢的顺序 array by push

,但是它现在在数组中有一个索引号。

有没有办法从数组中删除索引号

0 个答案:

没有答案