JavaScript code for displaying data sequentially one at a time

Hey there, I've developed a function that pulls data from a jsonp file. However, I'm looking to display this data one by one - starting with the vendor's name followed by their policyUrl.

  1. If you want to check out the source code, click on this link: https://github.com/neqts/jsonpPrint
  2. And here is the result of what I have created:

I could really use some assistance...

"use strict"

console.log(json)
const getNames = (obj) => Object.values(obj).map(el => el.name)

const purposesNames = getNames(json.purposes)
const vendorsNames = getNames(json.vendors)
const specialFeaturesNames = getNames(json.specialFeatures)
const specialPurposesNames = getNames(json.specialPurposes)
const stacksNames = getNames(json.stacks)


let outputArr = []
window.onload = function main() {

  const add = document.createElement('div')
  add.setAttribute("id", "demo");
  const overall = document.createElement('div')
  Object.entries(json.vendors).forEach(vendor => {
    outputArr.push(vendor[1].policyUrl) 
  })

  const add2 = document.createElement('div')
  document.body.appendChild(add2)
  const h1 = document.createElement('h1')
  add2.appendChild(h1)

  h1.innerHTML="GDPR consent"
  h1.style.cssText=`
  display:flex;
  justify-content:center;
  `
  
  const p2 = document.createElement('p')
  add2.appendChild(p2)
  p2.innerHTML=vendorsNames
  add2.classList.add('names')

  overall.appendChild(add);
  document.body.style.overflow="hidden"
   document.body.style.backdropFilter="blur(7px)";
   document.body.style.margin="0px"
   document.body.style.padding="21px"
  document.body.style.justifyContent="center"
  document.body.appendChild(add);
  document.body.style.background = "url(https://www.hgsm.pl/wp-content/uploads/2017/03/Pattern-Blue-Dots-background-patterns-pattern-wallpapers-1920x1080.jpg)"
  var final = document.getElementById("demo");
  final.innerHTML = outputArr;

      
  const add3 = document.createElement('div')
  add3.classList.add('butons')
  document.body.appendChild(add3)
  const accept = document.createElement('button')
  add3.appendChild(accept)
  accept.classList.add('btn1')
  const reject = document.createElement('button')
  add3.appendChild(reject)
  reject.classList.add('btn2')
  accept.innerHTML="ACCEPT"
  reject.innerHTML="REJECT"

  accept.addEventListener("click",show)
  reject.addEventListener("click",hide)
   document.querySelector('.butons')


  function show() {
   add2.style.display="none"
   add3.style.display="none;"
   final.style.display="none"
   document.querySelector('.butons').style.display="none"
   document.body.style.backdropFilter="none"
  }
  
  function hide() {
    add2.style.display="none"
    add3.style.display="none;"
    final.style.display="none"
    document.querySelector('.butons').style.display="none"
    document.body.style.width="100%"
    document.body.style.height="130vh"
  }  

    
  overall.style.cssText = `
      position: fixed;
      z-index: 1000;
      left: 0;
      top: 0;
      width: 100vw;
      height: 100vh;
      display: flex;
      align-items: center;
      justify-content: center;
      backdrop-filter: blur(7px);
  `;
  add.style.cssText = `
      display: flex;
      justify-content: center;
      align-items: center;
      width:90%;
      height: 90%;
      background: white;
      margin: 0 auto;
      font-size:7px;
  `;

  add2.style.cssText = `
    display: grid;
    justify-content: center;
    align-items: center;
    width:90%;
    height: 90%;
    background: white;
    margin: 0 auto;
    font-size:7px;
  `;
  add3.style.cssText = `
    display: flex;
    padding-top:20px;
    padding-bottom:20px;
    justify-content: center;
    align-items: center;
    width:90%;
    height: 90%;
    background: white;
    margin: 0 auto;
    font-size:7px;
  `;
}

Answer №1

Here is the solution you've been searching for

  const createNewDiv = document.createElement('div')
  Object.values(json.vendors).forEach(vendor => {
    const newParagraph = document.createElement('p');
    newParagraph.innerHTML = `${vendor.name}, <a href="${vendor.policyUrl}" >${vendor.policyUrl}</a>`;
    createNewDiv.appendChild(newParagraph);
  });
 document.body.appendChild(createNewDiv)

This code will display as shown below

https://i.sstatic.net/cs29T.png

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

Issue with formatting and hexadecimal encoding in JavaScript

I am currently developing a LoRaWAN encoder using JavaScript. The data field received looks like this: {“header”: 6,“sunrise”: -30,“sunset”: 30,“lat”: 65.500226,“long”: 24.833547} My task is to encode this data into a hex message. Bel ...

Trigger file download with ajax and php

I have been using an image picker plugin to select an image and then force it to download. Initially, I hard coded the PHP which worked perfectly fine. The download pop-up appeared and I was able to view the file without any issues. However, when trying to ...

The Javascript setTimeout Function Prolongs Its Operation

Currently, I have a web app index page that performs two main tasks. Firstly, it geocodes the user's location and stores it in a JavaScript variable called "variableToSend." Secondly, it sends this data to mySQL using a PHP script after a delay of 10 ...

Converting an array of date strings to a single string in JavaScript

Here is the JSON format I received with dynamic data: {"range":["2018-07-23T16:03:26.861Z","2018-07-23T16:03:26.861Z"]} Now, I need to convert this into the following format: range(20180723,20180723) Below is my code snippet : var data:Date[] = {"rang ...

Integrating chat functionality with a structured data format

Considering creating a collaborative communication platform, I am contemplating whether to develop a comprehensive application in JavaScript with MVC architecture or utilize it solely for managing message delivery using Node.js and socketIO. Would it be m ...

Data is not appearing as expected in the React component when using the data

I'm currently facing an issue while working with MUI. I am able to retrieve the list in console.log, but nothing is being displayed on the screen - no errors or data, just the console.log output. Here is a snippet of the data that I am receiving: ...

"Utilize an Ajax form with the 'post' method

I'm facing an issue with the AJAX form as it keeps throwing an error. I really need it to function properly when a button is clicked, refreshing all data in the process. <form name="form" id="form" class="form"> ...

Checking whether a node stream operates in objectMode

When working with a node js stream object, how can I ascertain if it is an object stream in objectMode? For example, suppose I have a readable stream instance: const myReadableStream = new ReadableStreamImplementation({ options: { objectMode : true } ...

Is there a quicker method to access an object's ID?

Within my array of objects, the structure is as follows: var locations = [ [{id: 1, lat: 51.52376322544537, lng: 5.13785702262885, content: 'Title A'}], [{id: 2, lat: 51.52358632767757, lng: 5.137921395645208, content: 'Title B'}], [{i ...

"Why does Sequelize migration successfully create a table, yet the models are unable to establish a connection to the

I am currently learning how to use the Sequelize ORM in Node.js and save data in a PostgreSQL database. My primary objective is to insert user data into the Users table. I have successfully created the table using migration; however, I am encountering dif ...

The $or operator in mongoose falls short in providing complete data when paired with the find() method

I am currently utilizing the find method in conjunction with the $or operator to search the database for any duplicate data within this specific line. const duplicate = await NewItemsData.find({ $or: newItems }); Upon inspecting the variable in the consol ...

"Learn the steps to access a JSON file directly from a URL within a Next.js

My goal is to upload a JSON file to the server from a URL, open it, parse it, and display its features on Google Maps. However, I am encountering an error with the "fs" library preventing me from opening the file. Below is the code: "use client" ...

Troubleshooting Angular 2: Instances of Classes Not Being Updated When Retrieving Parameters

I am facing an issue with the following code snippet: testFunction() { let params = <any>{}; if (this.searchTerm) { params.search = this.searchTerm; } // change the URL this.router.navigate(['job-search'], {q ...

Animate a div to sense whether it has reached the top or bottom position

Is it possible for a div to animate when it reaches almost halfway while scrolling? I'm looking to achieve this effect on a sticky sidebar, similar to how it works on this website: sample This is the code I have: $(function(){ // document ready ...

Displaying Text and Images on a Sliding Carousel with a Static Background Image

I am currently experimenting with the Materializecss Image Slider. My goal is to have a fixed full-screen background image while the texts and images slide over it. Initially, I tried setting the background-color of the slider class as transparent, but un ...

Dealing with null object values during Jackson parsing

I am currently utilizing the Jackson library and attempting to accomplish a task as described here BaseOperationRequest.java @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "command" ) @JsonSubTypes({ ...

Obtaining a response in string format using the $.ajax function

var module = (function(){ return{ loadData: function(url, success, error){ $.when($.ajax({ type: 'GET', cache: false, url: url, contentType: 'application ...

A guide to selecting the dropdown item labeled as (Select All) using Python and Selenium

edit: Trying to submit parameters for a database-generated report on this page. Successfully modified the start date in the first field using send_keys(), but unable to click on "(Select All)" for fields 3 and onwards, except one. In order to access the h ...

Encountered a 404 error while utilizing the Java - Angular web service

Encountering an error 404 in Firebug when attempting to send an object from Angular to a Java controller using JSON. While the backend in Java is able to receive the message, Angular is unable to find the specified path. Consequently, there is an issue wit ...

javascript conceal other sections upon hovering

There are 4 list items (<li>) that I want to use as triggers for linked images. In this project, I am using vanilla JavaScript as jQuery is not allowed. Below is the code snippet: var children = document.querySelectorAll('#resistorContent > ...