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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:57:27+00:00 2026-06-05T12:57:27+00:00

Is there a way to iterate over properties in an object without using a

  • 0

Is there a way to iterate over properties in an object without using a for in loop?

According to Nicholas C. Zakas, it takes 8x longer for a for in loop to iterate over an object than a for loop, but i cant find a way to iterate over the properties of an object without changing their names to something like 1, 2, 3 etc. witch isn’t ideal.

Speed is the main concern for me.

  • 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-05T12:57:30+00:00Added an answer on June 5, 2026 at 12:57 pm

    You can have another array that holds your keys. Something like this:

    var obj = {
        'key': 'value',
        'some': 'other value'
    },
        arr = [ 'key', 'some' ];
    
    for ( var i = 0, l = arr.length; i < l; i++ ) {
        console.log( obj[ arr[ i ] ] );
    }
    

    However, that’s ugly. Performance in this kind of case will never be your bottleneck, you should rather prefer readability. The code up there can be done this way:

    Object.keys( obj ).forEach( function( key ) {
        console.log( obj[ key ] );
    } );
    

    Which is just way cleaner and more readable. (for..in could also be used, it was just for the sake of the example)

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

Sidebar

Related Questions

Is there a way to iterate over every property of an object using the
Is there a way to iterate ValueCollection using straight for loop? (not foreach) e.g.
Is there a way to iterate (through foreach preferably) over a collection using reflection?
Is there any way to iterate over a Dictionary, in sorted order, sorted by
Is there a way to iterate over the keys, not the pairs of a
Is there a way to iterate over instances of a class in C#? These
Is there a way to iterate over Java SparseArray (for Android) ? I used
Is there a way to efficiently iterate over the values/items in a dictionary that
Is there a way to iterate over all my breakpoints in GDB and set
Is there a way to iterate over an n-dimensional array (where n is variable)

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.