How to rearrange an array by indices array?

前端 未结 9 1942
故里飘歌
故里飘歌 2021-02-01 19:12

Given an array arr and an array of indices ind, I\'d like to rearrange arr in-place to satisfy the given indices. For exa

9条回答
  •  情话喂你
    2021-02-01 19:54

    I am using ind as indexes in it's own order

    var arr = ["A", "B", "C", "D", "E", "F"];
    var ind = [4, 0, 5, 2, 1, 3];
    var obj = {}
    for(var i=0;i

    Working Fiddle

提交回复
热议问题