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

  • SEARCH
  • Home
  • 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 6774325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:46:24+00:00 2026-05-26T15:46:24+00:00

I have an object, defined thus: var obj = { ‘title’: ‘foo’, ‘id’: ‘123’,

  • 0

I have an object, defined thus:

var obj = {
    'title': 'foo',
    'id': '123',
    'category': 'aaa',
    'meta': 'blah blah'
};

I’d like to subset it, however, I discovered some behavior in JS which I don’t understand:

var foo = {obj.title: obj.id}; // doesn't work
var bar = {obj['title']: obj['id']}; // this doesn't either

var baz = {}
baz[obj.title] = obj.id // this works fine.

Why?

  • 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-26T15:46:25+00:00Added an answer on May 26, 2026 at 3:46 pm

    Because this is how it is defined in ECMAScript 5, Section 11.1.5:

    A property name must be either:

    PropertyName :
        IdentifierName
        StringLiteral
        NumericLiteral
    

    obj.title is neither an identifier name, nor a string or numerical literal. But even if you’d assign the title to another variable before, you see that the production rule does not evaluate the identifier:

    The production PropertyName : IdentifierName is evaluated as follows:

    1. Return the String value containing the same sequence of characters as the IdentifierName.

    Just to elaborate on why it is not a valid identifier name: The full stop (.) belongs in Puncuation, other [Po] category, which is not part of the allowed characters. These are, among others:

    UnicodeLetter:
    any character in the Unicode categories “Uppercase letter (Lu)”, “Lowercase letter
    (Ll)”, “Titlecase letter (Lt)”, “Modifier letter (Lm)”, “Other letter (Lo)”, or “Letter
    number (Nl)”.

    UnicodeCombiningMark:
    any character in the Unicode categories “Non-spacing mark (Mn)” or “Combining
    spacing mark (Mc)”

    UnicodeDigit:
    any character in the Unicode category “Decimal number (Nd)”

    UnicodeConnectorPunctuation:
    any character in the Unicode category “Connector punctuation (Pc)”

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

Sidebar

Related Questions

I have a serial of object defined as: public class Foo { public DateTime
I have a script which creates a user-defined object like this: obj = new
Well, the question is kinda simple. I have a object defined as: public class
I have a static object defined in my logging class, along the lines of:
Suppose I have an entity object defined as public partial class Article { public
Say I have a model object 'Person' defined, which has a field called 'Name'.
I have a struct defined like follows as part of an object. I'm trying
Suppose I have a user defined type: CREATE OR REPLACE TYPE TEST_TYPE AS OBJECT
I have a web page with swf file defined this way <object width=600 height=400
Lets say we have two objects o1 & o2 defined as System.Object, in my

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.