Displaying an error message in a spreadsheet cell

Issue

The problem arises when viewing the exported excel file where undefined is displayed. However, upon investigation, there are no empty array indexes causing this confusion.

Solution Attempt

const joinDate = new Date(obj.date);
let snap = [
    obj.name,
    obj.surname,
    obj.email,
    obj.nip,
    obj.phone,
    obj.address + " " + obj.home + " " + (obj.local=="brak" ? "" : obj.local),
    obj.city,
    obj.zip,
    obj.spentPoint,
    '',
    ''
];
orders.push(new Promise((resolve) => {
    let userNip = i;
    let ordersRef = firebase.database().ref('/orders/' + userNip);

    ordersRef.once("value", (snapshot) => {
        let ord = snapshot.val();
        let i = 0;

        for(let u in ord) {
            let o = ord[u];
            let newDate = new Date(o.date);
            let formattedDate = String(newDate.getDate()) + "/" + String(newDate.getMonth()+1) + "/" + String(newDate.getFullYear());
            snap[10+i] = formattedDate;
            for(let x in o.items) {
                snap[9+i] += String(o.items[x].title) + "[ Points: " + o.items[x].summary + " ]";
            }
            i = i + 2;
        }
        resolve();
    })
}));
data.push(snap);

In the excel sheet, the output appears as:

Name Surname ..... 1st product name, 1st product date, undefined2nd product name, 2nd product date.

The source of the undefined value remains elusive.

Upon thorough inspection, it is confirmed that the data array contains no missing values that could result in the appearance of 'undefined'.

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

A red line has been marked indicating the problematic area, persisting with the 3rd, 4th, and subsequent items...

Is there a solution to this issue?

Answer №1

snap[9+i] appears to be returning undefined. Why the use of 9 in this context? What about 10?

If you are attempting to access a specific element within the snap array, it is advisable to do so using a fixed index such as snap[1], snap[9], or snap[10].

The issue arises because you are combining 9 with 1 and trying to fetch the item at the 11th position or higher in an array that does not contain that many elements.

Edit:

If you need to maintain the current format for compatibility with certain external processes despite its limitations in data display, you might consider implementing something like the following:

const joinDate = new Date(obj.date);
let snap = [
  obj.name,
  obj.surname,
  obj.email,
  obj.nip,
  obj.phone,
  obj.address + " " + obj.home + " " + (obj.local=="brak" ? "" : obj.local),
  obj.city,
  obj.zip,
  obj.spentPoint,
];

  orders.push(new Promise((resolve) => {
  let userNip = i;
  let ordersRef = firebase.database().ref('/orders/' + userNip);

  ordersRef.once("value", snapshot=>{
    let ord = snapshot.val();

    for(let u in ord){
      let o = ord[u];
      let newDate = new Date(o.date);
      let formattedDate = String(newDate.getDate()) + "/" + String(newDate.getMonth()+1) + "/" + String(newDate.getFullYear());

      snap.push(formattedDate);
      for(let x in o.items){
        snap.push(String(o.items[x].title) + "[ Points: " + o.items[x].summary + " ]");
      }

    }
    resolve();
  })
}))
data.push(snap);

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

What is the best way to implement a subquery using EXISTS in Knex?

I'm currently facing challenges while constructing a query using knex, specifically when it comes to incorporating the 'WHERE' clause with the condition EXISTS (SELECT * FROM caregiver_patient WHERE patient_id IN (0,1)). Below is the origin ...

What is the best method for utilizing the jQuery Selector in this particular web application?

I have been attempting to figure out how to select a delete icon within my personal web application. delectIcon HTML <main> <div class="container"> <div class="tabs"> <a href=""><p><span class="act ...

Creating various containers in React JS for different components

I am faced with the task of rendering multiple DOM elements from my JavaScript code. Imagine I have div elements like this: <div id="div1"><div> //Some Html tags <div id="div2"><div> //Some Html tags <div id="div3" ...

Apple Safari 14.0.3 restricts JavaScript from setting a cookie expiry date beyond one week from the current date

This is my second time reaching out with this question, but after plenty of trial and error experimentation, I have gathered much more information to share. I have been attempting different methods to set a cookie in Safari using JavaScript 'document ...

Why does everything seem to move in sync with the table's scrolling?

I recently had an issue resolved that fixed most of my concerns: I needed to make three separate edits, and now when I reintroduce the other two edits, they are included within the table section and scroll along with the table instead of being stuck beneat ...

Preview not showing CSS changes properly

1) I am encountering an issue with displaying CSS in a form preview tab. Despite setting the CSS, it does not reflect on the fields after clicking the preview button. 2) Are there alternative methods to open the tab in a new window rather than opening it ...

Focus is lost on React input after typing the initial character

Whenever I input text, the focus is lost. All my other components are working fine except this one. Any ideas why this might be happening? I attempted to create separate components and render them in my switch statement, but it still doesn't work. O ...

Display Vue component using a string input

Is there a solution to make this non-functioning example work, or is its usage illegal? Vue.component('hello', { template: '<span>Hello world!</span>' }) Vue.component('foo', { data(){ return { ...

Encountering a 404 error in Angular MVC project while trying to load a

Trying to access an edit partial named AddEditPersonModal.cshtml from a different folder in my MVC project, in order to load its contents into a UI Bootstrap modal using Angular. However, when the index.cshtml page loads, I encounter a 404 error related to ...

React's Dynamic Table fails to rerender when updated values are placed in the same row and under the same header

Here is the table generated by my functional component: <table class="table"> {/* Consonant Table */} <tr> <th colSpan="2">---</th> {headersPOA. ...

Safari 15.6.1 does not support background video playback in Next.js

Currently using Safari version 15.6.1 for a small website project, I have encountered an issue where the video appears frozen with an arrow in the middle. Oddly enough, this problem only occurs on Safari as both Chrome and Firefox display the code correctl ...

Encountering an error with the node module timestampnotes: 'command not recognized'

I am encountering an issue while trying to utilize a npm package called timestamp notes. After executing the following commands: $npm install timestampnotes $timestamp I receive the error message: timestamp:126: command not found: slk Subsequently, I ...

Invoking a controller from another controller in the Express framework using Typescript

Currently, I am trying to call a controller from another controller in my code. While attempting to pass parameters using {params: {task_id: String(task_id), result}}, TypeScript is flagging an error indicating that res does not have all the required attri ...

The jQuery library triggers an error that can only be resolved by refreshing the

I am currently experiencing an issue with my form (form links are provided below, specifically referring to form1). The problem arises when I include jquery.js, as it fails to load the doAjax and getIP functions that are contained in a separate js file nam ...

Mismatch in SSL version or cipher for ExpressJS

I am encountering an issue with https in express and I am struggling to comprehend it: Here is the code snippet from my previous project (which functions correctly): index.js: var fs = require('fs'); var http = require('http'); var ...

Restrict access to table records by specifying an array of row identifiers

Hi everyone, I've encountered a small issue. Just to provide some background, I have a table with checkboxes. Each row in the table has an associated ID, and when selected, I receive an array like this: const mySelectedRoles = [1997, 1998, 1999] Once ...

Is there a way to store image URLs in a fashionable manner?

Hey there! I've been working on creating a HTML page that showcases multiple images. Everything is running smoothly on my localhost, but when I try to access it online, the images take forever to load. Any suggestions on how I can cache image URLs in ...

Using DefaultSeo does not override NextSeo in every component

I am looking to dynamically change the Head tag using next-seo. While browser validation will show NEXTSeo for individual pages, Twitter, Firebase's card validation tool, and others will default to next-seo-config.js. Does anyone have a solution? S ...

JavaScript hovering drop-down feature

Hi there, I'm just starting out with javascript and could use some help with a simple script. I have a shopping cart drop down that currently activates when clicked. However, I want it to fade in when hovered over instead. I've tried using .hove ...

Identifying a Malformed URI in JavaScript

In JavaScript, it is considered a best practice to use certain patterns to detect errors instead of solely relying on try-catch blocks. One easy way to do this is by using TypeError: if (typeof foo !== "number") { console.log("That ain't a number!" ...