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

280
Visualizações
How to change object key value number to string value

I am working on a project; the object has a dynamic key and a dynamic value. I will find which number the keys are holding, and change the number to string value, assuming the object list is too big to check each individually- more than 30 key values

const obj =  {
    one: 'jkej',
    two: 123,
    three: 'abc'
  }

Required output is

const obj =  {
    one: 'jkej',
    two: '123',
    three: 'abc'
  }

I want to change the what are the keys holding, and change the number value to string.

about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

You can loop the keys of the object and convert the values to string

Object.keys(obj).forEach((k) => {
  obj[k] = obj[k].toString()
})
about 4 years ago · Santiago Trujillo Relatório

0

You can do something like this

const obj = {
  one: 'jkej',
  two: 123,
  three: 'abc'
}

const convertToString = (object) =>
  Object.fromEntries(
    Object.entries(object)
    .map(([k, v]) => [k, v + ''])
  )


console.log(convertToString(obj))

about 4 years ago · Santiago Trujillo Relatório

0

You can iterate through the object and cast everything into a string using toString():

for (let [key, value] of Object.entries(myObject)) {
    value = value.toString()
}
about 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