I have two arrays, one of data and one of indices:
var data = [
'h', 'e', 'l', 'l', 'o', ' '
];
var indices = [
4, 0, 5, 0, 1, 2, 2
];
I would like to create a third array, using cells of data in order indicated in indices, so it here it would be:
['o', 'h', ' ', 'h', 'e', 'l', 'l']
I know I could easily do it with a simple loop:
var newArray = new Array(indices.length);
for (var i in indices) {
var index = indices[i];
newArray.push(data[index]);
}
But I wonder if there is a cleaner/simpler way to do it, like an array method or a special constructor ?