You can make one and have it available to all Arrays if you've no qualms about extending native prototypes in your environment.
Array.prototype.atIndices = function(ind) {
var result = [];
for (var i = 0; i < arguments.length; i++) {
if (arguments[i] in this)
result.push(this[arguments[i]])
}
return result;
}
var result = array.atIndices(1,3);
You could also have it check to see if an Array was passed, or a mix of indices and Arrays.
Array.prototype.atIndices = function(ind) {
var result = [];
for (var i = 0; i < arguments.length; i++) {
if (Array.isArray(arguments[i]))
result.push.apply(result, this.atIndices.apply(this, arguments[i]))
else if (arguments[i] in this)
result.push(this[arguments[i]])
}
return result;
}
This will actually flatten out all Arrays, so they could be as deeply nested as you want.
var result = array.atIndices(1, [3, [5]]);