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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:40:01+00:00 2026-05-15T17:40:01+00:00

When using a returned value to determine the number of an element in an

  • 0

When using a returned value to determine the number of an element in an array, does javascript throw quotes around it?

Example :

This tallys the number of times unique characters are used.

var uniques = {};

function charFreq(s)
{ 
    for(var i = 0; i < s.length; i++)
    {
       if(isNaN(uniques[s.charAt(i)])) uniques[s.charAt(i)] = 1;
       else uniques[s.charAt(i)] = uniques[s.charAt(i)] + 1;
    }

    return uniques;    
}

console.log(charFreq("ahasdsadhaeytyeyeyehahahdahsdhadhahhhhhhhhhha"));

It just seems funny that uniques[s.charAt(i)] works, and uniques[a] wont work (due to lack of quotes). uniques[a] will get you a nasty ‘a is undefined’.

  • 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-15T17:40:02+00:00Added an answer on May 15, 2026 at 5:40 pm

    When you access a JavaScript object using the [] notation, you are using a string as a key in the object. You can also address properties using the . notation:

    uniques.a is the same as uniques['a']

    The reason you aren’t adding quotes to the s.charAt(i) is that it returns a string, which is then used as the property to check on the uniques object.

    uniques[a] will create an error, because no variable with the name a has been defined.

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

Sidebar

Related Questions

yes what returned can be formatted using HH to display value in 24hrs, but
Does anyone have any experience of supporting multiple realms in HTTP Authentication? The Microsoft
I'm using a simple pexpect script to ssh to a remote machine and grab
I am adding a row using the clone() function and then am having to
This is one of the strangest errors I've ever seen. I'm doing a very
hey guys, what's you take on this. i want to set a header image
I've got a model which contains a List of QuestionEditModel for which I want
I'm trying to get the length of a string in order to format a
So I am trying to work with SQLite in one of iPhone applications and
Looking on some source code I've inherited, there's a snippet of code that calls

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.