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

123
Vistas
split object property value by comma and append with another property value

I have a below object

multiSpaceIdentityInformation =    
{
   roomNumber: "N/A"
   spaceNumber: "L1-008-5, L4-003, L1-009"
   spaceName: "Space, STUDIO, LOBBY"
}

I am looking to represent this with listed information like this below

const identityData = [
    { label: 'Room Number', value: multiSpaceIdentityInformation.roomNumber },
    {
      label: 'Space Info',
      value: `${multiSpaceIdentityInformation.spaceNumber} - ${multiSpaceIdentityInformation.spaceName}`
    }
  ];

  return (
    <Descriptions size="small" column={1} title="Identity">
      {identityData.map(({ label, value }) => (
        <Item key={label} label={<Text strong>{label}</Text>}>
          {value}
        </Item>
      ))}
    </Descriptions>
  );

What I am trying to represent in the spaceInfo label string looks like as this

L1-008-5 - Space, L4-003- STUDIO, L1-009 - LOBBY

But with the above code for the Space Info, it is printing like as this below

L1-008-5, L4-003 - Space, STUDIO ... and I am not sure where I am wrong with the above code, and could anyone please suggest any idea where it goes wrong.

Many thanks in advance

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

0

Piggybacking the other answer, with a different (I think simpler) construct, and producing the desired output without double spaces inside:

let m = {
   rnum: "N/A",
   snum: "L1-008-5, L4-003, L1-009",
   sn: "Space, STUDIO, LOBBY"
};

let snumA=m.snum.split(',');
let snA=m.sn.split(',');

console.log(
  snumA.map((item,idx)=>`${item} - ${snA[idx].trim()}`).join()   
);

about 4 years ago · Juan Pablo Isaza Denunciar

0

Do you expect something like this?

let m = {
   rnum: "N/A",
   snum: "L1-008-5, L4-003, L1-009",
   sn: "Space, STUDIO, LOBBY"
};


let snumA=m.snum.split(',');
let snA=m.sn.split(',');


console.log(
  snumA.reduce((r,i,idx)=>{
     r=`${r}${idx!==0 ? ',' : ''}${i} - ${snA[idx]}`
     return r;
  },'')   
)

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