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

The Archive Base Latest Questions

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

I have a variable length array of strings declared in javascript that contains Dungeons

  • 0

I have a variable length array of strings declared in javascript that contains Dungeons and Dragons class names. An example of this is below:

var class_names = new Array("Wizard", "Wizard", "Wizard", "Sorcerer", 
    "Sorcerer", "Ultimate Magus");

In my HTML, I use the javascript window.onload function to set a variety of variables from the javascript file to build the content of the page being displayed locally.

For things like name, this is easy:

document.getElementById('charname').innerHTML = name[0];

But for the class info, I don’t want to just pump out a massive string of class names, I want it condensed down. Using the example ‘class_names’ above, I want to end up with a string that looks like this:

“Wizard 3, Sorcerer 2, Ultimate Magus 1”

i.e. the number after each class name should be the number of repetitions found in the array.

Anyone have an idea how to make this happen on the fly, so when I alter the javascript file to add more class data to class_names, it is displayed appropriately on my HTML page?

Thanks in advance for any help I get on this pet project (namely creating a HTML page for each character in my campaign that can be printed out as a character sheet….it’s far better than manually writing a page for each character, or handwriting it on vanilla sheets).

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

    It’s easy enough, just loop through the array and count repetitions.

    var l = class_names.length, i, tmp = {}, ret = [];
    for( i=0; i<l; i++) {
        if( !tmp[class_names[i]]) tmp[class_names[i]] = 0;
        tmp[class_names[i]]++;
    }
    for( i in tmp) {
        if( tmp.hasOwnProperty(i)) {
            ret.push(i+" "+tmp[i]);
        }
    }
    // output is ret.join(", ");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that accepts a variable length array of 80 character strings.
I know that strings have variable length, therefore they need variable space in memory
I have list of unique variable length strings composed of letters, numbers and special
I have a ASCII file where every line contains a record of variable length.
I get this error in my c++ code Variable length array of non-POD element
I have been working on some legacy C++ code that uses variable length structures
I am attempting to store a variable length number that can have leading zeros
I have an array that created 5 objects. Each object has two strings and
I have an array called selectMe formed by a variable wich contains a string
I have an array filled with strings that have the same name as Google

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.