Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
is there a way to dynamically apply array mappers in TypeScript?

I need help. I'm trying to get data from an array but every time I add a new group filter (I'm working with a custom Kendo grid) what I receive is a nested array and if I want to get those data I need to add a map method on the new 'items' array. The problem is that I don't have only one group filter but I have too much of them. What can I do?

So every time I have to add another map method on items array and this is not very comfortable. There is a solution to my problem? I can get easily the number of the group filter.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can use flatMap convert e.g. [ [1, 2], [3, 4] ] to [1, 2, 0, 3, 4, 0] for arr.flatMap(v => [...v, 0]). In your case, this should have the same result:

const temp = this.result.data
    .flatMap(x => x.array)
    .map(y => y.selections)

This makes your code a lot more readable and easier to maintain and add to.

If you actually want to dynamically add map functions, you can do something like this:

const maps = [
    x => x.array,
    v => [v, v * 11],
    v => [v, -v],
    v => `num: ${v}`,
];

const data = [
    { array: [1, 2] },
    { array: [3] },
];

const temp = maps.reduce((data, map) => data.flat().map(map), data);
console.log(temp);

about 4 years ago · Juan Pablo Isaza Report

0

You could remove the forEach by replacing the first map as so:

this.result.data.forEach((x)=>{
  this.selections += x.array.map((y)=> y.selections)
})

It would help to have an example of what this.result and this.selections might contain

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!