Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

158
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda