How to get the specific data of a JSON with Angle 2x?

0

I have an answer that I transform into JSON this way:

const resposta = JSON.stringify(response);

              console.log(resposta);

Give me feedback on console.log like this:

[{"nome":"Ramos Janones","email":"[email protected]","cpf":"03472925698","celular":"34996320391","telefone":"","cep":"38300070","endereco":"DEZESSEIS","cidade":"Ituiutaba","estado":"Minas Gerais","bairro":"","complemento":"","usuario":"ramos","senha":"teste123","idppoker":"","nickppocker":"ramosinfo","numero":"","_id":"5bf18c512af2e61ab879d2f7","createdAt":"2018-11-18T15:59:13.735Z","updatedAt":"2018-11-26T15:41:00.806Z","__v":0,"id":"5bf18c512af2e61ab879d2f7","foto":{"_id":"5bfc140dbe257a17900442a1","name":"8.jpg","sha256":"Mt3053NTSRC81wiHOEMubEUagRAPlHOR-MtPvf2yKgQ","hash":"36cdc8491d7b4fa1817bed8126b3143e","ext":".jpg","mime":"image/jpeg","size":"58.46","url":"/uploads/36cdc8491d7b4fa1817bed8126b3143e.jpg","provider":"local","related":["5bf18c512af2e61ab879d2f7"],"createdAt":"2018-11-26T15:41:01.003Z","updatedAt":"2018-11-26T15:41:04.113Z","__v":0,"id":"5bfc140dbe257a17900442a1"},"contasJogadors":[]}]

How can I get the values I want to put in a localStorage?

I researched before posting this question, tried the various forms and did not work.

    
asked by anonymous 28.11.2018 / 17:08

1 answer

1
  

The map () method invokes the callback function passed by argument to   each element of the Array and returns a new Array as a result.

You could use the map array, it will loop and return a new array with whatever modifications you want, including removing or adding fields as needed:

var data = [{"nome":"Ramos Janones","email":"[email protected]","cpf":"03472925698","celular":"34996320391","telefone":"","cep":"38300070","endereco":"DEZESSEIS","cidade":"Ituiutaba","estado":"Minas Gerais","bairro":"","complemento":"","usuario":"ramos","senha":"teste123","idppoker":"","nickppocker":"ramosinfo","numero":"","_id":"5bf18c512af2e61ab879d2f7","createdAt":"2018-11-18T15:59:13.735Z","updatedAt":"2018-11-26T15:41:00.806Z","__v":0,"id":"5bf18c512af2e61ab879d2f7","foto":{"_id":"5bfc140dbe257a17900442a1","name":"8.jpg","sha256":"Mt3053NTSRC81wiHOEMubEUagRAPlHOR-MtPvf2yKgQ","hash":"36cdc8491d7b4fa1817bed8126b3143e","ext":".jpg","mime":"image/jpeg","size":"58.46","url":"/uploads/36cdc8491d7b4fa1817bed8126b3143e.jpg","provider":"local","related":["5bf18c512af2e61ab879d2f7"],"createdAt":"2018-11-26T15:41:01.003Z","updatedAt":"2018-11-26T15:41:04.113Z","__v":0,"id":"5bfc140dbe257a17900442a1"},"contasJogadors":[]}]

var maped = data.map(function(item){
  
  return {nome: item.nome, email: item.email}
})
console.log(maped)

Using the code simply return the fields you want and then save the new array as desired

  

link

    
28.11.2018 / 17:18