I have a collection of emails stored as a string that I would like to convert into a json or javascript object and store in a mongodb

After selecting multiple user emails, I receive the following data:

"participants" : "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="294b5b404847695d41405b4d5b465c5d4c074a4644">[email protected]</a>,<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1a74737175767b5a6e7f69767b34797577">[email protected]</a>,<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b8cbd7d5ddd7d6ddf8dfd5d9d1d496dbd7d5">[email protected]</a>",

However, my objective is to store them as a JSON or JavaScript object for tracking each email individually. The desired format is:

    "participants" : "{
                   {email:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="30524259515e704458594254425f4544551e535f5d">[email protected]</a}, 
                   {email:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="214f484a4e4d40615544524d400f424e4c">[email protected]</a>} 
                  }

I have a requirement to manage and process these emails separately in the future. To select multiple users, I utilized selectize.js which allows tagging list of emails.

Answer №1

emailsList = emailsList.split(",").map(emailAddress => ({emailAddress}));

Simply break down the email list into individual strings, then transform them into objects.

Answer №2

This is how I tackled the problem:

var members = "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f795859e9699b7839f9e85938598828392d994989a">[email protected]</a>, <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="412f282a2e2d20013524322d206f222e2c">[email protected]</a>, <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="70031f1d151f1e1530171d11191c5e131f1d">[email protected]</a>";     
var list = members.split(',');
        // console.log(list[0]);
        var j;
        var membersList = [];
        for (j = 0; j < list.length; j++) {
            membersList.push({ email: list[j] });
        }
        var objMembersList= JSON.stringify(membersList);
        console.log(objMembersList);

The resulting output appears as follows:

[{"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9ffaf2fef6f3aedff8f2fef6f3b1fcf0f2">[email protected]</a>"}, {"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="56333b373f3a6416313b373f3a7835393b">[email protected]</a>"}, {"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d9bcb4b8b0b5ea99beb4b8b0b5f7bab6b4">[email protected]</a>"}]

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 change the color of my Material Icons when I move my cursor over them?

Currently, I am integrating mui icons 5.2.0 into my React application. Although the icon appears on the page, it remains unchanged in color when I try to hover over it. Check out the snippet of code that I have implemented: import EditIcon from '@mu ...

The type string[] cannot be assigned to type 'IntrinsicAttributes & string[]'

I'm attempting to pass the prop of todos just like in this codesandbox, but encountering an error: Type '{ todos: string[]; }' is not assignable to type 'IntrinsicAttributes & string[]'. Property 'todos' does not ex ...

Tips for moving an element to the end of an array

Patients' data is stored in the MongoDB database, and all patients are mapped through on the frontend to display a list. An additional boolean value indicates whether a patient is archived or not. If a patient is archived, it should be displayed at th ...

Limit the outcomes of the Ionic timepicker

Currently, I am utilizing the ionic datetime feature. However, instead of receiving just the hours, minutes, and seconds, the result I am getting looks like this 2020-10-05T00:00:27.634+07:00. What I actually require from this output is only 00:00:27. Is ...

Tips for improving the loading speed of a table during scrolling with JavaScript

Is there a way to speed up the loading time of a <table> with 20000 rows? As I scroll through the page, it feels very sluggish and takes around 4-5 seconds to load the remaining table data. I'm unsure how to tackle this issue, which is why I h ...

Action creator incomplete when route changes

In my React-Redux application, there is an action creator that needs to make 4 server calls. The first three calls are asynchronous and the fourth call depends on the response of the third call. However, if a user changes the route before the response of t ...

Hough transformation in JavaScript with Node.js

Attempting to implement a 1-dimensional version of the Hough transform, focusing on optimizing for reduced dimensions based on minor properties. Included is the code and sample image with input and output visuals. Questioning what could be going wrong in ...

Having trouble displaying the Chrome context menu for a specific Chrome extension

I've read through several posts on this topic, but I'm still struggling to identify the issue with my implementation of the Chrome contextMenu API. I simply copied the code from a tutorial on Chrome APIs, and though there are no errors, the menu ...

Transferring a PHP session variable to JavaScript in a separate file

I successfully imported data from a CSV file into PHP and organized it into a nested array. To ensure the data is easily accessible across different files, I stored the array as a session variable. Now, the challenge lies in accessing this session variable ...

Checkmate with React Native's Checkbox Component

I have implemented the React Native Elements CheckBox inside List Items within a Flat List. import React, { Component } from "react"; import { View, Text, StyleSheet, FlatList } from "react-native"; import axios from 'axios&apo ...

Browserify does not provide access to the require function in the browser environment

I am currently in the process of developing a web application using node.js along with express. My goal is to leverage Browserify in order to expose my local modules to the browser. Here is the structure of my application: ├── app.js ├── lib ...

Loop through an array of objects that each contain two sub-objects using ng

I'm looking to organize each data-record in an object that contains two other objects structured like this: data Object { abbData={...}, invoiceData={...}} abbData Object { service="24", conn_fee="0", month_fee="249", more...} invoiceData ...

Understanding the concept of hoisting in JavaScript for global variables and functions

I've been curious about hoisting. I understand that if a global function shares the same name as a global variable, the function will overwrite the variable's name. Is this correct? Here is an example code snippet. (function() { console.log ...

JavaScript's wildcard character, *, in a regular expression will always match something

I am currently attempting to verify whether a given string contains only uppercase letters, numbers, and underscores by utilizing the pattern matching approach with /[A-Z0-9_]*/. Despite this, executing the following code results in a return of true: /[A ...

What is the best way to maintain the position of components (such as a Card component) when one is expanded in a Material-UI and ReactJS project

Currently, I am working with an expandable Card component from Material-UI and using flex for aligning the components. However, when one card expands, it affects the positioning of the other components in the row: https://i.stack.imgur.com/vGxBU.png What ...

Ensure all <li> tags within a HTML document exhibit consistent jquery mousedown and hover effects, abstaining from the assignment of unique IDs to each

I understand that this approach might not be correct, but I wanted to create a simulation of what I am trying to achieve. Is there a way for each <li> element within a specific <ul class="myul"> to have separate mousedown, mouseout, hover effe ...

I'm having trouble getting my HTML page to display appended text. What could be causing the issue?

let mainDiv = document.getElementById("main"); let myParagraph = document.createElement("p"); let myTextNode = document.createTextNode("hello"); myParagraph.append(myTextNode); mainDiv.append(myParagraph); let max = 25; let on ...

Encountering 404 errors when reloading routes on an Angular Azure static web app

After deploying my Angular app on Azure static web app, I encountered an error. Whenever I try to redirect to certain routes, it returns a 404 error. However, if I navigate from one route to another within the app, everything works fine. I have attempted t ...

Does Node.js support backward compatibility?

There is a common belief that Node.js is backwards compatible, meaning scripts running in Node.js N should also work in Node.js N+1. I have been unable to find any documentation confirming this assumption. Is there another way to verify compatibility aside ...

Error encountered: JSHint is flagging issues with setting a background gradient using

I have been experimenting with animating a background gradient using jQuery, and here is the code snippet I am working with: this.$next.css('line-indent', 0).animate({ 'line-indent': 100 }, { "duration": 750, "step": functi ...