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

208
Visualizações
Join elements of an object and exclude some

I have a Typescript project where I want to join all the values of an Object except one.

This is my Object:

let dataInit = {
  "host": "CAPR",
  "ua": "RMA",
  "country": "VE",
  "page":3
};

This is what I do:

let dataJoin = Object.values(dataInit).join(',')

This is what I get:

CAPR,RMA,VE,3

I need to know how to remove the 'page' property, this is what I want:

CAPR,RMA,VE
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

If you don't know the other attributes, you can first use Object.entries() to give you an array of arrays containing the keys and values. That array can then be filtered to remove the "page" element, mapped to just contain the value, and finally joined.

let dataInit = {
  "host": "CAPR",
  "ua": "RMA",
  "country": "VE",
  "page":3
};

console.log(
Object.entries(dataInit)
  .filter(([key,val]) => key !== "page")
  .map(([_,val]) => val)
  .join(",")
)

about 4 years ago · Juan Pablo Isaza Relatório

0

I would destructure the object first and create a new one

const { host, ua, country } = dataInit
const dataNew = { host, ua, country }

And then call the values join method on the new object.

about 4 years ago · Juan Pablo Isaza Relatório

0

You could filter the array resulted:

let dataJoin = Object.values(dataInit).filter(element => typeof element === "string").join(",");

Or you can use destructuring as presented in the other comments.

about 4 years ago · Juan Pablo Isaza 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