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 can I rename the "key" name of an object which is inside array in Node Js?

I am having trouble renaming the key of an object which is inside the array and not only this the name of the is empty as shown below

    {
   "success": true,
    "data": [
        {
            "": "abc123abc"
        }
            ]
    }

If I want to give the name to the key, how would I be able to do that in Node Js?

Like If want to give a key name like this shown below

    {
    "success": true,
    "data": [
        {
            "application_num": "abc123abc"
        }
    ]
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

There are two components to solving this issue - referencing the item with an empty name, and renaming it.

To reference any property, even with special characters or in this case an empty string, you can specify the property name as a string in square brackets like so:

data["my property with spaces"]
data[""]

Now that we can reference the empty property name, we now need to rename it. This can be achieved by deleting the original property and creating a new one with the same value. You can delete the property with the delete keyword, as follows

delete data[""]

Here is the complete final answer, which stores the value in a temporary variable, deletes the property you don't want, and assigns the stored value to a new different property name:

const data = {
   "success": true,
    "data": [
        {
            "": "abc123abc"
        }
            ]
    }
const dataObjectToModify = data.data[0]
const originalPropertyValue = dataObjectToModify[""]
delete dataObjectToModify[""]
dataObjectToModify["application_num"] = originalPropertyValue
about 4 years ago · Juan Pablo Isaza Relatório

0

a = {
   "success": true,
    "data": [
        {
            "": "abc123abc"
        }
            ]
    }

//{
//    "success": true,
//    "data": [
//        {
//            "application_num": "abc123abc"
//        }
//    ]
//}
//--------------------------------

a["data"][0] = {"application_num" : "abc123abc"}

//{
//    "success": true,
//    "data": [
//        {
//            "application_num": "abc123abc"
//        }
//    ]
//}

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