Having trouble displaying my JavaScript objects in distinct columns

I have encountered an issue where my 2 Javascript objects are not displaying in separate columns on the DOM. The requirement is to showcase the details of two individuals on a 2 Column page, with one person's information on each side.

My approach involved using a loop to append data to the two div columns that I had created. Within the body, there is a div container with distinct id attributes for appending purposes.

sabio.page.startUp = () => {

  people = [{
      "firstName": "John",
      "lastName": "Doe",
      "age": 23,
      "streetAddress": "123 Main St.",
      "city": "Culver City",
      "state": "CA",
      "zip": 92340
    },
    {
      "firstName": "Juan",
      "lastName": "Doe",
      "age": 47,
      "streetAddress": "123 Main St.",
      "city": "Culver City",
      "state": "CA",
      "zip": 92340
    }
  ]
  console.log(people);

  sabio.page.mapObjFunc(people);
}



sabio.page.mapObjFunc = person => {
  for (let i = 0; i < people.length; i++) {

    console.log(i);
    $("#div" + i).append("<h1>" + i + ": " + people[i] + "</h1>");
    people[i] + "<br>";
  }
}
<div class="container">
  <div class="row">
    <div class="col-sm-6" id="div0">
      <h1>Column 1</h1>
    </div>
    <div class="col-sm-6" id="div1">
      <h1>Column 2</h1>
    </div>
  </div>
</div>

The desired outcome is to have both people object displayed on the DOM in individual columns. Despite deploying my code live, I am not encountering any error messages.

Answer №1

The items stored in the individuals array are all unique entities. To properly analyze each entity, you must iterate through and list out their characteristics. Below is the updated script:

for (let i = 0; i < individuals.length; i++) {
  let person = individuals[i];
  let details = '<div>';
  for (let prop in person) {
     details += prop + ' ' + person[prop] + '<br>'
  }
  details += '</div>';
  $("#cont" + i).append("<h1>" + i + ": " + details + "</h1>");
}

Answer №2

I'm not sure why there's a break tag after the append line. Also, it seems like you've already closed your append function.

Could it be meant to look more like this?

for (let i = 0; i < people.length; i++) {
        console.log(i);
        $("#div" + i).append("<h1>" + i + ": " + people[i] + "</h1><br>");
        //people[i] + "<br>"; <-- This is an error
  }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Drop-down and autocomplete feature in Material UI design framework

Encountering an issue with aligning a label with a dropdown in material UI, and for some reason, this behavior is observed: https://i.sstatic.net/n7pj8.png Struggling to get them aligned on the same row. This is the code snippet of my component: const us ...

Error occurred while trying to create module 'app' in Angular and MEAN stack

Recently, I delved into the MEAN stack using Express, Node, Jade, and Angular. However, it seems like there's a problem with Jade that I can't quite wrap my head around. The error message I'm getting is: Uncaught Error: [$injector:modulerr] ...

Determine the width of two inline input fields

Showing two inputs side by side: +------------+ +--------------------------+ | ID='inputA'| | ID='inputB' | +------------+ +--------------------------+ +------------------------------------------+ A ...

Comparing Chaining jQuery Functions with If Statements in Checking Check Box Values

I'm working with multiple checkboxes and trying to determine the overall value for them all. For example, if one checkbox is checked then the value should be true/selected. If none are checked, then it should be false/unchecked. The HTML code I am ...

What steps can I take to modify this HTML code so that my Tumblr background does not repeat and covers the entire page?

body { color: #1a1a1a; font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: 19px; background: url('http://www.totallylayouts.com/backgrounds/hipster/triangle_in_the_woods.jpg') no-repeat top left scroll; Even after attemp ...

Using an SVG filter to create a solid blue color overlay on an image

For a while now, I've been applying -webkit-filter: grayscale(100%); to render an image in grayscale. But recently, I've been wondering if it's possible to tint the image blue instead. My initial thought was to utilize an SVG filter and refe ...

What steps can be taken to create a curved bottom for the header section?

While I've seen this question asked before, I'm not satisfied with how the design has been implemented. Here is my desired look for the curved header I've experimented with border radius left and right, but the edges are excessively rounde ...

Python 3.7 and Unicode-objects in an Array

I'm grappling with an encoding issue in my second python project since I lack experience in this area. The problem appears to be stemming from an array within the code. Despite attempting to pre-encode both inputs and '297aae72' using this m ...

Tips for utilizing MUI Typography properties in version 5

I'm clear on what needs to be done: obtain the type definition for Typography.variant. However, I'm a bit uncertain on how to actually get these. interface TextProps { variant?: string component?: string onClick?: (event: React.MouseEvent&l ...

Positioning two buttons with one on the left and the other on the right

I am currently looking to add an ADD button next to the VIEW button in this layout. An example of what I am trying to achieve can be seen at where you can click on the GRID VIEW icon. <div class="desktop_view product-view grid-list-row-view hide" sty ...

display the chosen choices from the jquery tool

I have implemented a Jquery movie seat selection plugin on my jsp website successfully. It allows users to select seats with ease. However, the issue I am facing is that due to my limited knowledge of Jquery, I am unable to display the selected seats by t ...

Nav bar taking up full width of page, centered to the right with content area

I am facing an issue with aligning my full-width navbar with my fixed content area. The ul keeps changing based on the browser or resolution. Check out this fiddle for reference: http://jsfiddle.net/fwyNy/ subject site CSS Code: #topribbon{ width: 10 ...

Incorporate seamless integration by using the npm install command

I am currently facing an issue where I need to identify and remove unused dependencies from my package.json file every time I run npm install for my app. Is there a method to automatically include the npm package https://www.npmjs.com/package during the n ...

Converting a string into a Date in Typescript while disregarding the timezone

Upon receiving a date in string format like this (e.g.): "11/10/2015 10:00:00" It's important to note that this is in UTC time. However, when creating a Date object from this string, it defaults to local time: let time = "11/10/2015 10:00:00"; let ...

Is there a way for me to handle state changes within a controller for nested views?

Currently, I am attempting to execute a resolve function upon a state change in order to retrieve data that I need to inject into a controller that utilizes "multiple" views. The rationale behind having nested views is due to the presence of a template/app ...

Converting a String Matrix into a Multi-Dimensional Array Using PHP

If I have a string that is structured like this: 293545 974256 947276 How can I efficiently convert it into a two-dimensional array in PHP, where each row corresponds to the newlines and each digit is an element within the array? This needs to be done co ...

When using `mongoose find({})`, the callback function is not automatically triggered

I have implemented a static function in my Mongoose model, defined in a separate file where I extend the schema before creating the model. The function looks like this: 'use strict'; exports.statics = { list : function (options, cb) { ...

"Using more than one tab at the same time is causing disruptions

My current project involves using a jquery plugin for image annotation. Within my application, I have multiple images displayed in different tabs. Initially, I attempted to organize these tabs using foundation tabs but encountered the same issue when trans ...

Automated HTML loader

I have a webpage that utilizes AJAX to load portions of HTML content. These fragments contain images, some of which are specified in a separate CSS file using background-image properties. I am trying to implement a pre-loader so that the loaded content w ...

Change an Object to an Array of Objects with the Array maintaining the same type as the original Object

I have a method that transforms an Object into an Object Array. I am aware that I could achieve this using new [] {obj} However, the resulting Array would be of Type object[]. I wish for the Array to be of the same Type as what obj.GetType() returns! I ...