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

168
Vistas
Javascript : How to add comma to string element in interface

Hi have below structure for user interface -

export interface IUser {
  EMPLOYEE_NAME :string,
  EMPLOYEE_PID : string
}

At a point in a code , I am receiving array of IUser - IUser[] with multiple employeenames and their pids.

Eg.

{EMPLOYEE_NAME:'XYZ',EMPLOYEE_PID :'A123'},
{EMPLOYEE_NAME:'ABC',EMPLOYEE_PID :'B123'},

I want to fetch comma seperated PIDs - 'A123','B123'

I tried with map and foreach but not able to loop properly as its interface.

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

0

You can use Array.prototype.map and Array.prototype.join to achieve.

let data = [{EMPLOYEE_NAME:'XYZ',EMPLOYEE_PID :'A123'},
{EMPLOYEE_NAME:'ABC',EMPLOYEE_PID :'B123'}];

let result = data.map(x => x.EMPLOYEE_PID).join(',');
console.log(result);

If you want to wrap the ids in comma

let data = [
  {EMPLOYEE_NAME:'XYZ',EMPLOYEE_PID :'A123'},
  {EMPLOYEE_NAME:'ABC',EMPLOYEE_PID :'B123'}
];
let result = data.map(x => `'${x.EMPLOYEE_PID}'`).join(',');
console.log(result);

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can also use Array.prototype.map.call to achieve.

    const data = [
     {EMPLOYEE_NAME:'XYZ',EMPLOYEE_PID :'A123'},
     {EMPLOYEE_NAME:'ABC',EMPLOYEE_PID :'B123'}
    ];

    Array.prototype.map.call(data,
        function(item) { 
            return item['EMPLOYEE_PID']; 
        }
    ).join(",");

Output - 'A123,B123'

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