Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

42
Views
Create an array of objects, having an array of data in JavaScript

this time I come to you for the following, I want to create an object in JS with data that comes to me from an array, the array contains the following data:

const columnsTable = [
  "id",
  "name",
  "age"
];

Really the problem is that when this happens in vuejs it returns me as follows and it is exactly the same code, any idea? what is selected is the return of my computed method My computed method is as follows: method computed My computer method has the same native js code and it returns me differently. Would it be good to open another question with this topic?

The array of objects that I want to create with the above array must have the following structure:

 columns: [
        {
          name: 'id', align: 'center', label: 'id', field: 'id'
        },
        {
          name: 'name', align: 'center', label: 'name', field: 'name'
        },
        {
          name: 'age', align: 'center', label: 'age', field: 'age'
        }
      ]
    } 

Where each object represented in the object array has a value from the columsTable array in name, label and field.

I am trying as follows but I am not successful:

var columnsTable = [
  "id",
  "nombre",
  "edad",
];

var colums = [];

columnsTable.forEach((column) => {
  colums.push({
    name: column,
    align: 'center',
    label: column,
    field: column
  });
  console.log(colums);
});

Since this at the end returns all the values of my array within a property of my object. From now on I thank you, any contribution would be very helpful.

7 months ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.