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

169
Views
Assign a property of nested array inside a new string array

I'm new in VueJs and Typescript, so I have four interfaces:

export interface ShipMethodResponse {
  companyTypeList: CompanyType[]
}

export interface CompanyType {
  companyTypeId: string
  companyTypeName: string
  companyList: Company[]
}

export interface Company {
  companyId: string
  companyTypeId: string
  companyName: string
  companyAbbreviation: string
  companyDescription: string
  companyWebsite: string
  shipMethodList: ShipMethod[]
}

export interface ShipMethod {
  shipMethodId: number
  companyId: string
  shipMethodName: string
}

Each one can have an array of the next interface if you read from top to down.

So I want to insert into a new array of a string the property companyName of Company interface, so I try:

data() {
    return {
      shipMethodList: [] as string[],
      ...
    }
  },

  methods: {

    async myMethod() {
      //companyTypeList is a CompanyType array

      var b = companyTypeList.map((e) => ({
        companyList: e.companyList,
      }))

      for (const c of b) {
        var company = c.companyList.map((company) => ({
          companyName: company.companyName,
        }))

        this.shipMethodList.push(company)
      }


    }
    }

But when I try to push the company it is throwing

Argument of type '{ companyName: string; }[]' is not assignable to parameter of type 'string'.

How can I create a list of all "companyName" property? Regards

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

0

I think the problem is here:

var company = c.companyList.map((company) => ({
    companyName: company.companyName,
}))

You say you want to create string[], but that map function creates { companyName: string }[]

Change it to this:

var allCompanyNames = c.companyList.map(
    company => company.companyName
)

UPDATE

What you really want is probably this:

for (const c of b) {
    for(company of c.companyList) {
        this.shipMethodList.push(company.companyName)
    }
}
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!