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

142
Views
How to transform an array of arrays into an object with index signature?

So I have two types B and A, and an array a, which I should transform into type B.

type A = Array<[string, number, string]>;

type B = {
    [name: string]:
        {
            name: string,
            age: number,
            city: string
        }
}

const a: A = [
    ['name1', 10, 'city1'],
    ['name2', 33, 'city2'],
    ['name3', 61, 'city3'],
    ['name4', 60, 'city4']
];

export const b: B = ???

I have no understanding how can I transform an array because of index signature [name: string] in type B. Usually I transform through array.map(value => {}), but here I can't find a way to include index signature in map method.

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

0

B describes an object of the shape:

export const b: B = {
  name1: {
    name: 'name1',
    age: 10,
    city: 'city1'
  }
};

but if you want an array of Bs you can

export const b: B[] = a.map(([name, age, city]) => ({ [name]: { name, age, city } }));
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!