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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:46:45+00:00 2026-05-31T16:46:45+00:00

Taking a JavaScript object with 4 properties: function Object() { this.prop1; this.prop2; this.prop3; this.prop4;

  • 0

Taking a JavaScript object with 4 properties:

function Object() {
  this.prop1;
  this.prop2;
  this.prop3;
  this.prop4;
}

var obj = new Object();

I use a for(in) loop to inspect each property since I don’t know the number or name of the properties:

for(property in obj) {
  var prop = obj[property];
}

However I would like to process the properties starting with the last (prop4 in this example). I suppose I would like a reverse-for-in-loop.

How can I do this?

Thanks,
Jack

Adding: The object I am referring to is the one returned from JSON.parse. The properties seem to be consistently ordered. There is no keys() method.

  • 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-31T16:46:47+00:00Added an answer on May 31, 2026 at 4:46 pm

    A for (x in y) does not process the properties in any specific order so you cannot count on any desired order.

    If you need to process the properties in a specific order, you will need to get all the properties into an array, sort the array appropriately and then use those keys in the desired order.

    Using ES5 (or an ES5 shim), you can get all properties into an array with:

    var keys = Object.keys(obj);
    

    You could then sort them either in standard lexical order or sort with your own custom function:

    keys.sort(fn);
    

    And, then you could access them in your desired order:

    for (var i = 0; i < keys.length; i++) {
        // process obj[keys[i]]
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is an object: var obj = new function(){ this.prop = {}; } and
Taking the jQuery framework for example, if you run code like this: $(document).ready(function init()
Is it possible to create a new Location object in javascript? I have a
I'm basically trying to create a generic object in javascript that I can use
I hope someone can help me with this Javascript. I have an Object called
I am taking an object-oriented approach to building a Javascript app. For starters, I
I am taking a javascript new Date() and trying to format it as a
I am taking an XML feed and writing it to HTML using JavaScript. The
After taking a look at this SO question and doing my own research, it
So taking a look at the API doc page here: http://developers.facebook.com/docs/reference/javascript/FB.api I'm wondering if

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.