Unfortunately, I don\'t have JQuery or Underscore, just pure javascript (IE9 compatible).
I\'m wanting the equivalent of SelectMany() from LINQ functionality.
<
Here you go, a rewritten version of joel-harkes' answer in TypeScript as an extension, usable on any array. So you can literally use it like somearray.selectMany(c=>c.someprop)
. Trans-piled, this is javascript.
declare global {
interface Array {
selectMany(selectListFn: (t: TIn) => TOut[]): TOut[];
}
}
Array.prototype.selectMany = function ( selectListFn: (t: TIn) => TOut[]): TOut[] {
return this.reduce((out, inx) => {
out.push(...selectListFn(inx));
return out;
}, new Array());
}
export { };