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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:30:25+00:00 2026-06-17T17:30:25+00:00

I am using an object as a hash table and I have stuffed both

  • 0

I am using an object as a hash table and I have stuffed both regular properties and integers as keys into it.

I am now interested in counting the number of keys in this object which are numbers, though obviously a for (x in obj) { if (typeof x === "number") { ... } } will not produce the result I want because all keys are strings.

Therefore I determined that it is sufficient for my purposes to assume that if a key’s first character is a number then it must be a number so I am not concerned if key “3a” is “wrongly” determined to be a number.

Given this relaxation I think i can just check it like this

for (x in obj) {
  var charCode = x.charCodeAt(0);
  if (charCode < 58 && charCode > 47) { // ascii digits check
     ...
  }
}

thereby avoiding a regex and parseInt and such.

Will this work? charCodeAt is JS 1.2 so this should be bullet-proof, yes?

Hint: I would love to see a jsperf comparing my function with what everyone comes up with. 🙂 I’d do it myself but jsperf confuses me

Update: Thanks for starting up the JSPerf, it confirms my hope that the charCodeAt function would be executing a very quick piece of code reading out the int value of a character. The other approaches involve parsing.

  • 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-17T17:30:26+00:00Added an answer on June 17, 2026 at 5:30 pm

    Why speculate when you can measure. On Chrome, your method appears to be the fastest. The proposed alternatives all come at about 60% behind on my test runs.

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

Sidebar

Related Questions

I'm using a hash table (DotNET Dictionary object) as part of a sparse two-dimensional
I need to create a new Hash object using two arrays. But, the conditions
Is there any way to get the previous hash using the history object ?I
I am recrusively evaluating properties via reflection using object.GetType().GetProperty(string propertyName). This is working fine
I have a byte[] that i obtained using Object ArrayList<Obj> Can anyone tell me
I'm building a javascript application using object oriented techniques and I'm running into a
I am building a web application and have been told that using object oriented
I built a symbol table using an array list filled with an object pairs
I have created a hash table that will keep as a key a string
I have a problem. Currently i'm using Lazyloading to load images and data into

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.