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 7808607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:11:02+00:00 2026-06-02T03:11:02+00:00

The following code : var obj = {uname:OdO, age:22}; alert(obj.uname); results in: OdO Now,

  • 0

The following code :

var obj = {uname:"OdO", age:"22"};  
alert(obj.uname);

results in:

OdO 

Now, using the same concept in a for..in statement :

for (x in obj) {
    document.write(obj.x+"<br>");
}

I expected it to print the following:

OdO  
22 

but it prints :

undefined  
undefined

And to achieve printing looping in the elements, it should be written as an array elements like this:

for (x in obj) {
    document.write(obj[x]+"<br>");
} 

Then, why the first syntax doesn’t work, however it works out of the for..in statement ?

  • 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-06-02T03:11:06+00:00Added an answer on June 2, 2026 at 3:11 am

    When you write obj.x, this literally looks for a property named “x” in obj — just like obj.size would look for a property named “size”. x is not defined for your objects, so it comes out as nothing. The correct way of writing it — obj[x] — uses the variable x to look up a property in the object. The bracket syntax uses the value inside the brackets to look up the property, while the dot syntax turns the property name into a string. So these two are equivalent:

    obj.x
    obj["x"]
    

    So when you write x after obj., it converts that x into a string — it’s not a variable anymore.

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

Sidebar

Related Questions

I have the following code (I am using the jQquery libary): var obj =
I have the following code segment: var run = 0; var obj = {'item1':0,'item2':5,'item3':10};
Take the following code as a sample: procedure TForm1.Button1Click(Sender: TObject); var Obj: TSomeObject; begin
Consider the following code. var sParent:Sprite = new Sprite(); var obj:Sprite = new Sprite();
Lets say I've run the following code: var toType = function(obj){ return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase(); };
Suppose I have the following code: function DoSomething:Boolean; var obj : TMyObject; i :
The following code: var constant = Expression.Constant(find me, typeof(string)); // memberExpression evaluates to a
I have the following code: var submitHandler = function ($link, $form, close) { var
I have the following code: var refreshId = setInterval(function() { $(#footad).html('myjshere'); }, 15500); Where
I have the following code: var carsContext = new CarsDataContext(); IQueryable<Car> allCars = carsContext.Cars;

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.