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

199
Visualizações
How to make new array with old array in Javascript

I'm trying to clean a this array:


 [
    {
      "Cpf": null,
      "Nascimento": null,
      "Sexo": null,
      "OnlyPerson": false,
      "IsFinanc": false,
      "Senha": null,
      "ConfirmaSenha": null,
      "Remover": false,
      "TipoStr": null,
      "FiltroStr": null,
      "IdAgenciaLogarComo": 0,
      "DontHashPass": false,
      "IsPessoaSimples": false,
      "IsVisitante": false,
      "Permited": false,
      "Id": 21980,
      "Nome": "arrozfeijao",
      "Ativo": true,
      "Criacao": "2021-08-19T14:09:06.173",
      "UltimaAlteracao": null,
      "Email": "arrozfeijao@gmail.com",
      "IdAgencia": 1,
      "IdEndereco": null,
      "IdPermissao": 4,
      "Observacoes": null,
      "Endereco": {
        "Id": 0,
        "Cep": null,
        "Logradouro": null,
        "Numero": null,
        "Complemento": null,
        "Bairro": null,
        "Estado": null,
        "Cidade": null
      },
      "Parceiro": null,
      "Contato": [],
      "Permissao": {
        "Id": 4,
        "Descricao": "Cliente",
        "Pessoa": []
      },
      "AlterarSenha": [],
      "Rede": [],
      "Provider": [],
      "AlertaPreco": [],
      "Pedido2": [],
      "_PageNumber": 0,
      "PageNumber": 0,
      "PageSize": 0,
      "OrderBy": null,
      "OrderDesc": false
    }
  ]

This array is a checkbox selected in a table -> enter image description here I need a function to clean array fo every time I select one more checkbox. I has tryied to push all I need to new a variable, but if a select other checkbox (with other informations) dont work...

I need export to CSV this informations, but I don't need all this, I just wanna:

  • "Cpf"
  • "Nascimento"
  • "Sexo"
  • "Id"
  • "Nome"
  • "Ativo"
  • "Criacao"
  • "UltimaAlteracao"
  • "Email"
  • "Observacoes"
  • "Endereco".

I know a i need a for, i just do no how to make this function :c

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

As it looks like your data belongs to one person and there could be multiple persons, here is a solution:

Declare your arrays:

data: function () {
  return {
    oldArray: [],
    includesArray: ["Cpf", "Nascimento", "Sexo", "Id", "Nome", "Ativo", "Criacao", "UltimaAlteracao", "Email", "Observacoes", "Endereco"],
    newArray: []
  }
}

oldArray would the the data from your question, includesArray are the keys you want to transfer to the new array and newArray will have this data.

Add this to you component:

created() {
    for (const [key] of Object.entries(this.oldArray)) {
      let tempObject = {};
      for (const [keys, values] of Object.entries(this.oldArray[key])) {
        if (this.includesArray.includes(keys)) {
          tempObject[keys] = values;
        }
      }
      this.newArray[key] = tempObject;
    }
  }
about 4 years ago · Juan Pablo Isaza Relatório

0

You can use Lodash pick method to pick the properties from object and you can map it and the pseudo-code is

let newArray = oldArray.map(item => {
return _.pick(item, ['id', 'name']);
});
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