Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

206
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!