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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:27:29+00:00 2026-06-18T05:27:29+00:00

I have a base array of 6 different words that represent game elements. Just

  • 0

I have a base array of 6 different words that represent game elements. Just wondering how I would multiply the number of instances of each word within the array.

var gameItem = [cattle, wood, stone, metal, grain, craft];

That is, say I want 10 instances of each word to be added to the array, how would I do that? Order isn’t important as it’ll be shuffled.

  • 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-18T05:27:30+00:00Added an answer on June 18, 2026 at 5:27 am

    Don’t forget that your array doesn’t work unless you define each of those variable. But as I understand, those are words, not vars. So the right array declaration is:

    var newGameItem = ["cattle", "wood", "stone", "metal", "grain", "craft"]
    

    To repeat that array 10 times, you can use a for loop and the array method concat().

    var newGameItem = [];
    for(var i=0 ; i<10 ; i++) {
        newGameItem = newGameItem.concat(gameItem);
    }
    
    > newGameItem : ["cattle", "wood", "stone", "metal", "grain", "craft", "cattle" ... ]
    

    I don’t know what is your idea for this, but, if you want to store a quantity of elements of those kinds, like, player has 1 cattle, 12 wood, 20 stone, etc …
    You probably should have a better data structure, like this:

     var gameItem = {"cattle" : 1, "wood" : 12, "stone" : 20, "metal" : 0, "grain" : 0, "craft" : 0 };
    

    So by doing gameItem.wood, you get the result > 12

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

Sidebar

Related Questions

I have an array of pointers to a base class, so that I can
I have a number of classes that reflect tables in a database. I would
I have a base class object array into which I have typecasted many different
In the project I'm working on now, we have base Entity class that looks
I have a base class ( car ) and a class that inherit the
Drupal 6.x I have this module that manages four different content types. For that
How to compare the similarity between two arrays? Say I have: Base Array: [.5,0,0,0,.25,0,0,.25,0,0,0,0]
I have a problem. I'm trying to create an array of different class objects
I have a JSON-array containing objects of different types with different properties. One of
Basically, I have an array like this: val base_length = Array( 0, 1, 2,

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.