Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

139
Vistas
how to convert an array to a array of objects with additional information in react using map when doing a POST api request

I'm new with react and I'm stuck at a problem, kindly help me. array looks like this: surveyors=[jj,kk]

The length of array can be variable i.e.there can be more values. what i want to send in post api is:

data:[
   { 
    name:"kk",
    is_active:True,
    company:26
    },
    {
    name: "jj",
    is_active:True,
    company:26
    }
 ]

I'm using postapi like this:

  const postURL = moduleURL("url");
      requests({
        method: "post",
        url: postURL,
        data: [
          
          { 
    name:"kk",
    is_active:True,
    company:26
    },
    {
    name: "jj",
    is_active:True,
    company:26
    }
    
      ],
      })
        .then((response) => {
          console.log(response);
          
        })
        .catch((err) => console.log(err));
    }

if there was a fixed data i could do it but since the data in array surveyor is variable i cannot fix it. note- company here is the company id that i have stored in a variable and it will be same for every object in array and is_active will always be true.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

var supervisor=["jj","kk"];
var result = supervisor.map(s => {return {name: s, is_active:true, company:26} });
console.log(result)
about 4 years ago · Juan Pablo Isaza Denunciar

0

use map to create a new array of objects with extra attributes;

const supervisors = ["jj", "kk"];
const modifiedSupervisors = supervisors.map(item => ({name: item, is_active:true, company:26}));

now you can use this data in api call data: modifiedSupervisors,

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda