Typescript - convert array.map to array

148 Views Asked by At

I wanted to emulate C# Linq select. And bind result to Devextreme DataGrid.

I get objects implemented:

export interface A { b: B[]; }
export interface B { c: C; }

I can make an array by collecting all the Cs and DataGrid works fine with test1:

let test1 = [];

for (var k in this.a.b)
  test1.push(this.a.b[k].c);

But if I try map as masses of blogs suggest for linq.Select the DataGrid doesn't display any data with test2:

let test2 = a.b.map(i => i.c);

Question - is result of array.map an array?

1

There are 1 best solutions below

1
On

They both have the same contents and point to the same objects (c objects in this case), however are different arrays. To compare equality for an array of objects, you would want to iterate over each element and verify equivalence.

const isEqual<T extends object>(a: T[], b: T[]): boolean {
   // ... iterate and check each value
}