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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:16:51+00:00 2026-05-23T09:16:51+00:00

I am a newbie in JS. Here is my code and I believe it

  • 0

I am a newbie in JS. Here is my code and I believe it should work… but it doesn’t.

var pop = new Array();
pop['la'] = new Array('nt','gb','te');
pop['sa'] = new Array('nt','gb');
pop['ha'] = new Array('pc','pa');
var _ecpop="la";

for (var i = 0; i < pop[_ecpop].length; i++)
{
    document.write(pop[_ecpop][i]);
}

I just do not know any alternate way to have a map of vectors of a string.

Thanks,

Amir.

  • 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-23T09:16:52+00:00Added an answer on May 23, 2026 at 9:16 am

    That’s not an Array, but a Javascript Object, containing Arrays in it’s properties. You can use Object and Array literals for that. The advantage is that your code looks much cleaner. There are seldom reasons to use new Array or new Object in javascript code (see for example this SO Question).

    var pop = {
      la: ['nt','gb','te'],
      sa: ['nt','gb'],
      ha: ['pc','pa']
    }
    

    now you can use

    for (var i = 0; i < pop.la.length; i++) { 
     console.log(pop.la[i]);
    } 
    

    if a property label is stored in a variable (like you _ecpop), you can use bracket notiation to retrieve it’s value:

    var laArr = pop[_ecpop];
    for (var i = 0; i < laArr.length; i++) { 
     console.log(laArr[i]);
    }
    

    The other way around you can assign a label to an Object:

    var _ecpop = 'la';
    pop[_ecpop] = ['nt','gb','te'];
    

    document.write is not the preferred way to put things on your page. It’s better and just as easy to use some element with an id, and write output to it using innerHTML, for example

    document.getElementById('myOutput').innerHTML = '[some output here]';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Java newbie here, I'm having trouble setting a new line in this code: String
JavaScript newbie here, I was going through some js code at work when i
I am a total Groovy newbie. I saw the following code here . def
Extreme Android developer newbie here...well, new to Android development, not development in general. I
Newbie here. I have this code: while (v < 360) { v +=10; RunIt();
python newbie here. I'm writing the code to control an experiment that has multiple
Newbie here (to C, objective-C, and iOS)... For this code in my AppDelegate.m, why
Perl newbie here...I had help with this working perl script with some HASH code
A JavaScript newbie here. I have this following code: function testObject(elem) { this.test =
Jquery newbie here =) so I've got a code that slides the menu divs

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.