Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 807273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:22:42+00:00 2026-05-15T00:22:42+00:00

This looks like a very simple issue, but I just can’t get it to

  • 0

This looks like a very simple issue, but I just can’t get it to work.

I have a Javascript object like this:

var person = {};
person.one = {gender: 'male', name: 'John'};
person.two = {gender: 'male', name: 'Doe'};
person.three = {gender: 'female', name: 'Jane'};

Then I have some HTML like so:

<a id="one">click</a>
<a id="two">click</a>
<a id="three">click</a>

Now, I need to get the correct object value by the id of the clicked link. So basically, I need to dynamically access the 1st-level object keys without a for-loop, since the keys are strings.

I’ve tried this:

$('a').click(function() {
   alert(person[$(this).attr('id')['gender']]);
});

It didn’t work. Neither did this:

$('a').click(function() {
   alert(person.($(this).attr('id')).gender);
});

All I get back is an “uncaught exception: Syntax error, unrecognized expression”. Obviously, my syntax is way off.

I’ve already read through many posts on here, but couldn’t find the solution. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T00:22:42+00:00Added an answer on May 15, 2026 at 12:22 am

    To access a property with a dynamic name like you’re going for, the correct syntax is to use brackets, like an array.

    alert(person[$(this).attr('id')].gender);
    

    Or it might just be cleaner-looking to pull that ID into a separate variable:

    var id = $(this).attr('id');
    alert(person[id].gender);
    

    Your call 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a very simple WPF UserControl that looks like this: namespace MyUserControl {
I've got a very simple WPF UserControl that looks like this: namespace WpfControlLibrary1 {
I have a very large file that looks like this (see below). I have
Okay. I know this looks like the typical Why didn't he just Google it
I have a class that looks like this public class SomeClass { public SomeChildClass[]
Looks like I am struck with a simple issue. I am hosting a precompiled
There might be some very simple answer to this, but i am really stuck
I know at first glance (due to the title) this looks like one of
Update: looks like this is indeed a WiX limitation - Cannot add 64bit com+
My code looks like this NSNumber *inputToNumber = [NSNumber numberWithFloat:[textField.text floatValue]]; the value from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.