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

207
Visualizações
Get value from object parsing selected value

I have some date like this:

const data = {
  first: {
    segment: 'first',
    segment_id: '257ad548-6fee-47c1-afbc',
    placeholder: 'Some text'
  },
  second: {
    segment: 'second',
    segment_id: '373273a0-208f-4c3f-905b',
    placeholder: 'Some random text'
  },
  third: {
    segment: 'third',
    segment_id: '26e96613-1180-4961-b775',
    placeholder: 'Another random text'
  },
  fourth: {
    segment: 'fourth',
    segment_id: '03451a57-8d95-4113-b109',
    placeholder: 'Totally random text'
  },
};

And a selext box:

<select id="segments">
  <option selected="selected" value="257ad548-6fee-47c1-afbc">first</option>
  <option value="373273a0-208f-4c3f-905b">second</option>
  <option value="26e96613-1180-4961-b775">third</option>
  <option value="03451a57-8d95-4113-b109">fourth</option>
</select>

How can I get data from the object based on the selected value? This is what I have tried:

document.getElementById('segments').onchange = function () {
    selectedSegment = this.options[this.selectedIndex].text;
    console.log(data.selectedSegment.placeholder); // Not working - it's undefined
    // I'm looking for this value in the data object: data."selected text".paceholder
}

JsFiddle

Hope my question makes sense. :-) Thank you.

about 4 years ago · Juan Pablo Isaza
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