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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:55:29+00:00 2026-06-13T17:55:29+00:00

I would appreciate some help. I am trying to do a small javascript program

  • 0

I would appreciate some help. I am trying to do a small javascript program that does the following:

1) I already have a few arrays with some information about different cars. For example:

var brand = ["Audi", "Ford", "Peugeot", "Nissan"];
var color = ["red", "black", "black", "white"];

2) Then, I would like to create a class that creates a new car and receives the properties through a method that retrieves them from the ones I have stored in the array,

Is something like this correct?

function newcar() {
    this.prototype.loadinfo = function() {
        var cbrand = brand[0];
        var ccolor = color[0];
    }
}

Sorry if this is horribly wrong, but the reason I am asking is that I didn’t find any information about this particular case on the webpages I checked. Since I am trying to learn javascript just with internet tutorials, I tried to guess the solution as good as I could!

And in case it’s correct (sort of) or that the correct version is very similar, I cannot understand how I should advance in the array while I create new cars. For example, if I run it once, the first car created will receive the information on the position [0], but if I run it twice or more times… how can I know in which position of the array I should find the information?

I am quite confused with this subject. I will be very grateful if someone can give me some advice. In the meantime, I continue reading about it, to see if I find out something else.

Thanks!

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

    If I understand correctly you want to create a new car object for as many brands in the array. The first thing is to fix your constructor. Note that constructors are capitalized as a convention and the prototype should be declared outside, but you don’t need the prototype because you’re dealing with unique properties not shared methods. Then you can pass 2 parameters that will be assigned to the properties. In other words:

    function Car( brand, color ) {
      this.brand = brand;
      this.color = color;
    }
    

    If you need a method to read those properties add it to the prototype like:

    Car.prototype = {
      loadInfo: function() {
        alert( this.brand +':'+ this.color );
      }
    };
    

    Finally, to create a new car for every item in the array you’d do it like this:

    var cars = [];
    for ( var i = 0; i < brand.length; i++ ) {
      cars.push( new Car( brand[i], color[i] ) );
    }
    

    Now you have 4 cars in the cars array, and each car will be a different brand and color.

    But better yet, you can organize your brands and colors in an object and a for...in to create new cars:

    var cars = {
      Audi: 'red',
      Ford: 'black',
      Peugeot: 'black',
      Nissan: 'white'
    };
    
    var mycars = [];
    for ( var c in cars ) {
      mycars.push( new Car( c, cars[c] ) );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would appreciate some help with something I working on and have not done
I have a problem finding references to this subject and would appreciate some help.
I seem to have hit a wall here and would appreciate some help from
I really have not worked much with XML and I would appreciate some help.
I would appreciate some help with an UPDATE statement. I want to update tblOrderHead
I would appreciate some help on creating the proper SQL to retrieve only one
I'm pretty new to Python programming and would appreciate some help to a problem
I'm a newbie in Spring Batch, and I would appreciate some help to resolve
I would really appreciate it if some of you could help optimize my tables,
I made the following small Javascript script to enable some form elements on my

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.