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

159
Vistas
How to join/add strings in an array object

I've an array which has objects inside it:

[
{pointID: 1, pointName: "One" },
{pointID: 2, pointName: "Two" },
{pointID: 3, pointName: "Three" }
]

I would like to join all the strings i.e pointName like this : "One-Two-Three"

Any help is appreciated. Thanks.

Edit 1:

This is what I tried so Far:

this.viaPoints.forEach(x=> {      
      var splitted = x.pointName.split(" ");    
      console.log('I5: ',splitted[0].join("-"));
     });

The reason I've split is because the string will have extra characters some times like "One - A". So I've used split to remove the extra

Edit 2: In my case this helped as I mentioned above that to remove extra characters and strings:

var permittedValues1 = this.viaPoints.map(value => value.pointName.split(" ")[0]).join("-") ;
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You can use Array.prototype.reduce function to return an array which contains pointName for each object in the array and join all value of the return array with -.

let data = [
  {pointID: 1, pointName: "One" },
  {pointID: 2, pointName: "Two" },
  {pointID: 3, pointName: "Three" }
]

let result = data.reduce((accumulator, current) => {
    return accumulator.concat(current.pointName);
}, []).join('-');

console.log(result);

over 4 years ago · Santiago Trujillo Denunciar

0

You can use .map and .join functionalities too. Here .map will take the values based upon the key-pointName and .join is used to return an array as a string. The elements will be separated by a specified separator (here "-").

let array = [
      {pointID: 1, pointName: "One" },
      {pointID: 2, pointName: "Two" },
      {pointID: 3, pointName: "Three" }
      ];
var permittedValues = array.map(value => value.pointName).join("-") ;
over 4 years ago · Santiago Trujillo 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