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

202
Views
How to return variable as array in vuejs

I am trying to return a variable as an array like [ 'Google', 'Facebook', 'Twitter', 'Apple', 'Oracle' ]

But what I am getting is

Google
Facebook
Twitter
Barishal
Oracle

My code from setup() :

const stringOptions = axios.get('https://api.com').then(response 
 => {
        Object.keys(response.data.divisions).forEach(key => {
          var a = response.data.divisions[key].name
          console.log(a)
        })
    })
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can simply achieve this by using Object.keys() along with Array.map() method.

Try this :

const divisions = {
  0: {
    name: 'Google'
  },
  1: {
    name: 'Facebook'
  },
  2: {
    name: 'Twitter'
  },
  3: {
    name: 'Barishal'
  },
  4: {
    name: 'Oracle'
  }
};

const res = Object.keys(divisions).map(key => divisions[key].name);

console.log(res);

about 4 years ago · Juan Pablo Isaza Report

0

Another approach using Object.values along with Array.map()

const divisions = {
  0: {
    name: 'Google'
  },
  1: {
    name: 'Facebook'
  },
  2: {
    name: 'Twitter'
  },
  3: {
    name: 'Barishal'
  },
  4: {
    name: 'Oracle'
  }
};

const res = Object.values(divisions).map(division => division.name);

console.log(res);

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!