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

99
Visualizações
Store object values into an array

I've this piece of code, it retrieves a list of 'Client' where FULL_NAME like a KEY I input.

[
  {
    id(pin):1
    full_name(pin):"James Marius Bolord"
    email(pin):"mariusjames32@gmail.com"
    phone(pin):"9832910293"
    dob(pin):"1981-05-05"
    location(pin):"REXDALE"
    user_id(pin):1
  },
  {
    id(pin):23
    full_name(pin):"Carl Barard"
    email(pin):"mariusjames32@gmail.com"
    phone(pin):"9832910293"
    dob(pin):"1981-05-05"
    location(pin):"REXDALE"
    user_id(pin):1
  },
  {
    id(pin):9
    full_name(pin):"Tony Falape"
    email(pin):"mariusjames32@gmail.com"
    phone(pin):"9832910293"
    dob(pin):"1981-05-05"
    location(pin):"REXDALE"
    user_id(pin):1
  }
]

Now I learn that you can make use of object by doing this:

const zoo = {
  lion: '🦁',
  panda: '🐼',
};

Object.keys(zoo);
// ['lion', 'panda']

Object.values(zoo);
// ['🦁', '🐼']

Object.entries(zoo);
// [ ['lion', '🦁'], ['panda', '🐼'] ]

Until there, everything is fine on my mind. What I would like to do is having this type of result from that object:

const full_name = [
    "James Marius Bolord",
    "Carl Barard",
    "Tony Falape",
   
  ];

So every time I type a key in, it should create an array of the full_name Key of the Client Table. I would appreciate the suggestion and ideas.

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

0

Ignoring the typo in your desired result, if all you want is to extract full names from your array of objects, then use Array.prototype.map:

const full_name = data.map(entry => entry.full_name);

If you want to implement some kind of autocomplete/autosuggest feature, <datalist> is a very good candidate for your use-case:

const data = [{
    id: 1,
    full_name: "James Marius Bolord",
    email: "mariusjames32@gmail.com",
    phone: "9832910293",
    dob: "1981-05-05",
    location: "REXDALE",
    user_id: 1
  },
  {
    id: 23,
    full_name: "Carl Barard",
    email: "mariusjames32@gmail.com",
    phone: "9832910293",
    dob: "1981-05-05",
    location: "REXDALE",
    user_id: 1
  },
  {
    id: 9,
    full_name: "Tony Falape",
    email: "mariusjames32@gmail.com",
    phone: "9832910293",
    dob: "1981-05-05",
    location: "REXDALE",
    user_id: 1
  }
];

const full_name = data.map(entry => entry.full_name);
console.log(full_name);

// Populate datalist as a UI/UX feature
const datalist = document.querySelector('#fullnames');
data.forEach(entry => {
  const option = document.createElement('option');
  option.value = entry.full_name;
  
  datalist.appendChild(option);
});
<input list="fullnames" />
<datalist id="fullnames"></datalist>

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