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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:59:45+00:00 2026-06-05T20:59:45+00:00

I am trying to select an object from this array and print all of

  • 0

I am trying to select an object from this array and print all of its properties into an element, using “data-id”. How would I go about doing this? Also, how can I give an ID to the new CarObjects?

**<div id="carInfo" data-id="10"></div>**

function Car(company, name, price, details, image, alt){ 
    this.company = company;
    this.name = name;
    this.price = price;
    this.details = details;
    this.image = image;
    this.alt = alt;
}

var carInformation = [new Car("Ferrari", "Marenello", " $250,000", "Fast. Very Fast.", "images/ferrari.jpg","image of ferrari"),
                      new Car("Dodge", "Viper", " $100,000","Great Acceleration","images/dodge.jpg", "image of viper"),
                      new Car("Ford", "Shelby", "$80,000", "Muscle Car", "images/mustang.jpg", "image of mustang"),
                      new Car("Back To The Future", "Delorean", "$20,000", "Travels through time","images/delorean.jpg", "image of delorean"),
                      new Car("Lamborghini", "Diablo", "$250,000", "Fastest","images/lambo.jpg","image of lamborghini"),
                      new Car("CMercedes Benz", "SLR", "$180,000", "Classy Vehicle.","images/benz.jpg","image of mercedes benz"),
                      new Car("Chevrolet", "Corvette", "$70,000", "Fiberglass body Light Vehicle.","images/vette.jpg","image of corvette"),
                      new Car("Porsche", "Carrera", "$120,000", "Great Handling.","images/porsche.jpg", "image of porsche"),
                      new Car("Audi", "R8", "Price: $110,000", "Fast and Classy.", "images/audi.jpg","image of audi") ];
  • 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-05T20:59:47+00:00Added an answer on June 5, 2026 at 8:59 pm

    jQuery lets you get the data-id attribute via the data() method;

    var carInfo = carInformation[$('#carInfo').data('id')];
    
    Object.keys(carInfo).forEach(function (val) {
        console.log(val + " is " + this[val]);
    }, carInfo);
    

    The above snippet uses code from the ECMAScript5 specification, which is not supported in older browsers. If you wish to support them, you need to make use of a ES5 shim or polyfiller, or use the snippet below:

    var carInfo = carInformation[$('#carInfo').data('id')];
    
    for (var x in carInfo) {
        if (carInfo.hasOwnProperty(x)) {
            console.log(x + " is " + carInfo[x]);
        }
    }
    

    Printing it into an element depends on how you want it formatted, but the above code will give you all the details you should need to be able to do this.

    EDIT: Bear in mind that your carInformation array only has 8 elements in it…

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

Sidebar

Related Questions

I am trying to select the last record from a table in MySQL using
I need to get all the rows from result object. I’m trying to build
I am trying to use a hashtable so I can select a specific object
I trying to select all li elements at second level of the list add
When trying to select fields from a subquery if ANY of the subqueries do
I am trying to select three values from xml document. I want to get
I am trying to select only the topmost section H1s. In this fiddle ,
I'm trying to select all dom elements that have id=mydiv but exclude the ones
I'm running a query that looks like this: $results = $DB2->query(SELECT COUNT(*) FROM auth_user
Ok, so the issue is coming from trying to pull data from a sqlite

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.