Creating HTML for an email by iterating through a JavaScript object

I need assistance with iterating through a JavaScript object where each key:value pair is displayed on separate lines in the email body using Appscript. I believe it might need to be converted to an HTML string but I'm not entirely sure. The code snippet I currently have is as follows:

let data = {}
  const information = dataRange.filter(function(row) {
    return row[0] >= result && row[10] != 'Gratitude' && row[10] != 'Notes' && row[10] != ''
  }).map(function(row) {
    return data[row[0]] = row[10]
  })

var message = {
    to: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a0d0c5d2d3cfce91e0c7cdc1c9cc8ec3cfcd">[email protected]</a>',
    subject: 'Weekly Summary',
    body: 
    `
    This week's summary:
    
    ${data}`,
  }
  MailApp.sendEmail(message);

Any guidance would be highly appreciated.

Thank you!

Answer №1

If you'd like a simpler approach, consider using an array that can be easily converted into a text string using the .join() method. Below is a revised version to try out:

  const content = dataRange
    .filter(row => row[0] >= result && row[10] !== 'Gratitude' && row[10] !== 'Notes' && row[10] !== '')
    .map(row => [row[0], row[10]].join(': '))
    .join('\n');
  const emailMessage = {
    recipient: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c2b2a7b0b1adacf382a5afa3abaeeca1adaf">[email protected]</a>',
    subject: 'Weekly Summary',
    messageBody: 'List of completed tasks for this week:\n\n' + content,
  };
  MailApp.sendEmail(emailMessage);

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

Tips for creating a custom Angular Material modal window that is fully responsive to its parent modal window

Hey there! I've put together a custom modal window in Angular Material by combining the custom modal window example with the Angular Material slider demo. Everything is working well except for the fact that the sliders inside the modal window are not ...

What steps can I take to detect errors when generating a MongoDB ObjectId in Node.js?

var selectedCriteria = Mongoose.Types.ObjectId(payloadData.skillId), If an incorrect Id is passed, the following error message will be displayed: Error: Uncaught error: Argument passed in must be a single string of 12 bytes or a string of 24 hex charac ...

Issues with installing global NPM packages

Recently, I developed a command line tool in JavaScript that allows users to back up data to IPFS. https://www.npmjs.com/package/ipfs-backup However, when I tried to install it using npm install -g ipfs-backup, there was an error that prevented the packa ...

When I start scrolling down, the Jumptron background image vanishes

Utilizing bootstrap jumptron with a background image has led to an issue where the background image disappears as I scroll down, leaving only the jumptron div class displaying the heading. How can this be fixed so that the image remains visible even when s ...

Discovering the XPath of an element

Can anyone help me locate the XPath for the hamburger navigation icon on the website , specifically in the upper left corner? I am developing a Python script using selenium and need it to be able to click this particular button. Here's what I have tr ...

Seeking a solution for resizing the Facebook plugin comments (fb-comments) using Angular when the window is resized

Is it possible to dynamically resize a Facebook plugin comment based on the window or browser size? I want the fb-comment div to automatically adjust its size to match the parent element when the browser window is resized. <div id="socialDiv" class="c ...

Discovering a particular element involves iterating through the results returned by the findElements method in JavaScript

I am attempting to locate and interact with a specific item by comparing text from a list of items. The element distinguished by .list_of_items is a ul that consists of a list of li>a elements. I am uncertain about how to transfer the determined elemen ...

Adding data to a JSON object using AngularJS

When attempting to insert an object into a JSON object, I am encountering an issue where it duplicates the JSON object. Here is a breakdown of the scenario: <input type="text" style="width: 40% !important;" placeholder="Nom" class="input-sm" ng-model= ...

Looking to store HTML form data in MongoDB and showcase the saved information on a webpage using AngularJS, ExpressJS, and NodeJS

Client-side : Example HTML Code <body ng-controller="myAppController"> <nav class="navbar navbar-inverse"> <div class="container-fluid"> <div class="navbar-header"> <h1>person details</h1> </div> ...

Vanishing message when clicked in PHP

I created a code to display error messages and success messages based on user input, allowing them to click anywhere on the screen to dismiss the message. The issue I am facing is that when the user receives both a success and an error message simultaneo ...

Issues with UA PhoneGap 2.0 plugin failing to initialize properly on iOS device

In my attempt to integrate push notifications into my iOS PhoneGap 2.0 app using the recently released Urban Airship plugin, I encountered an issue. Everything functions perfectly when I load the index.html from the provided sample application into my proj ...

View a specific selected newsAPI article on its own dedicated page

I have been working on a news website and successfully displayed all the articles on a single page using the news API in nodeJs. Everything is functioning well, but now I want to show the clicked article on a separate page. Although I managed to route it t ...

Loop through each item in the JSON object

After making an ajax call, I receive a json object in the success callback with the following structure: {test 1: Array(2), test 2: Array(3), test 3: Array(2)} The arrays inside each key have elements that look like this: 0: {IdProduct: "1", ProductName ...

Can you explain the concept of middleware and the app.use method in Express?

Before we dive in, I just want to clear the air that this might seem like a repeat question. However, I am curious to hear your explanation of what middleware is. I've noticed similar inquiries on Stack Overflow, but I'm hoping you can provide so ...

What is the best way to display the size of this JSON Object?

Struggling to output the length of this JSON Object on the console, but all I get is 'undefined'. This JSON data is encoded in PHP and then sent back via ajax to an unnamed function as 'msg' {"1":{"item_id":"shirt_straight--small","qu ...

Error in Angular 2 (CLI) Routing: Unable to process (Error reading property 'split' of undefined)

What could be the reason why routing is only working for the first imported component after AppComponent (for example, "PageNonFound")? I also encountered an error after implementing routing in my project. Error Error in ./AppComponent class AppComponent ...

Methods for extracting the date value from a Material UI datepicker?

As a newcomer to React, I am currently working on creating a form that includes a Date picker for scheduling appointments. Since booking appointments in the past is not allowed, I need to disable the days before today in the calendar for the date picker. ...

Rails - Issue with jQuery/AJAX causing partial not to refresh

Currently, I have a timeline view that displays event partials, allowing users to create, read, update, and delete events directly on the timeline. However, I am facing an issue where the delete partial does not refresh after deleting an event, requiring t ...

"Creating eye-catching popup images in just a few simple steps

<div className="Image popup"> <Modal isOpen={modalIsOpen} onRequestClose={closeModal} contentLabel="Image popup" > <img src="../img/navratri-1.png" alt="Image popup" /> <b ...

Tips for inserting data into a PHP modal using MySQL and Ajax

Here is the code snippet I've written: <div class="container"> <div class="row"> <div class="col-md-3"> <div id="accordion" role="tablist" aria-multiselectable="true"> <div class="card"> ...