What is the best way to concatenate a data object?

This task should be quite straightforward.

Using Vanilla JS, I am trying to update the content of a span element with the session ID obtained from a function call.

Here's an example:

sessionId = 0_77b1f7b5-b6c8-49a0-adbc-7883d662ebba
document.getElementById("sessionID").innerHTML = sessionId

However, when I run this code in my HTML/JS files, it doesn't seem to have any effect.

Running the same snippet in the Browser Console produces the following error message (observed in Firefox and Chrome):

Uncaught SyntaxError: numeric separators '_' are not allowed in numbers that start with '0'

I require the session ID to retain its original format (with '0' and underscore).

After consulting the Firefox documentation (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Identifier_after_number), I learned that enclosing the value in quotation marks like '0_77b1f7b5-b6c8-49a0-adbc-7883d662ebba' resolves the issue.

However, when attempting to convert this data into a string using String(), I encounter difficulties.

Object { sessionId: "0_77b1f7b5-b6c8-49a0-adbc-7883d662ebba", modules: (1) […] }

sessionId = String(setupCompleteData.sessionId)

console.log("TEST : ", sessionId)

TEST :  0_77b1f7b5-b6c8-49a0-adbc-7883d662ebba

Do you have any suggestions on how to work around this issue?

Thank you very much!

Answer №1

It appears that there is no necessity to convert the sessionID into a string since it is already in that format...

Directly assigning this variable to textContent resolved the issue. It turns out that using .value wouldn't update the span.

Resolution :

document.getElementById("sessionID").textContent = setupCompleteData.sessionId

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 are the steps to take in order to successfully deploy an Express server on GitHub Pages?

I heard that it's possible to host an Express server on GitHub Pages, but I'm not sure how to do it. Is the process similar to deploying a regular repository on GitHub Pages? ...

Focus Google Map on Selected Option using AngularJS

I'm attempting to center the map based on a selection in a drop-down select option box. Despite trying various examples, I haven't been successful in getting the map to recenter to the new latitude and longitude coordinates. I'd like to ach ...

JavaScript code for opening and closing buttons

I created a button that successfully opens, but I am struggling to figure out how to close it. Can someone assist me with this? Additionally, I have one more query: How can I remove the border when the button is clicked? document.getElementById("arrowb ...

Utilizing Sequelize's Where clause with the flexibility of optional parameters

Can you guide me on writing Sequelize queries with optional parameters? Consider the below query example: const result : SomeModel[] = await SomeModel.findAll( {where: { id: givenId, ...

Cloud Foundry deployment faces startup issues

I attempted to deploy my Node.js application on Bluemix, but encountered a failure. After executing cf logs IssueTracker --recent, I came across the following error: 2018-12-10T16:50:24.38+0000 [APP/PROC/WEB/0] ERR module.js:549 2018-12-10T16:50:24 ...

Is it possible to prompt npm to install a sub-dependency from a GitHub pull request?

Currently, I'm in the process of setting up geofirestore, which has a dependency on geofirestore-core. However, there is an existing bug in geofirestore-core that has been addressed in a pull request. How can I make sure that my geofirestore installa ...

Click the "Login" button using Jquery to gain access

Whenever I hit the Login button, a 500 Internal server error pops up in the console. Can someone guide me on the correct way to perform a POST request using jQuery? I would really appreciate any help. <button class="login100-form-btn" type=& ...

When a specific JavaScript function is triggered, the value of an HTML control will reset to its original default value

I have a form with a specific requirement. I need to allow users to input data in a text field and press enter, which should dynamically create new controls like another text field, a dropdown menu, and another text field using jQuery. While the functional ...

What changes can I make to this jquery code to utilize a background image instead of a background color?

Can someone help me modify this snippet to set a background-image instead of changing the background color? <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("#button_layer").hide(); $("#im ...

Executing a sequence of jQuery's $.when().then() functions

I am facing challenges in understanding how to properly sequence my functions, especially in relation to the $.when() method. function y() { defer = $.Deferred(); $.when(defer).then(console.log(defer.state())); } y(); <script src="https://ajax.go ...

Align images of varying sizes vertically within div containers, even when the image is larger than the div itself

I'm facing a challenge when it comes to aligning images vertically inside divs. The problem arises due to the following conditions: The images will have varying and unknown sizes. These images are larger than the divs they are contained in, requiri ...

jqGrid: What could be causing the events I defined for grid edit to not fire?

I've been attempting to make in-line edits on a grid, but it seems like none of the events connected to those edits are being triggered. I am specifically looking to use afterSubmit: so that it triggers after the user has edited the Quantity field in ...

What is the best way to have a sound play when the page is loaded?

Is there a way to automatically play a sound when the page loads? <audio src="song.mp3"> Your browser does not support the audio element. </audio> I've attempted it with the following method: <script type="text/javasc ...

The state returned by React Redux does not meet the expected results

I recently implemented a like function on the backend using Node and MongoDB. This function successfully returns the post with an updated likes counter, which I tested using Postman. The post object contains properties such as likes, _id, by, createdAt, an ...

JavaScript effectively divides multiple child dropdowns with the main dropdown, thanks to Bootstrap innovation

I have implemented a jQuery function to dynamically change multiple child dropdowns based on the selected value of the main dropdown. For reference, you can view the image here. However, I encountered an issue when applying the Bootstrap styles "form-con ...

Javascript chart

Hello everyone, I am diving into the world of fetch API. Currently, I am faced with a challenge where I need to generate the following list items: <li>Zimmerman, Paul</li> <li>Yimmerman, Raul</li> <li>Limmerman, Caul</li> ...

I'm looking for recommendations on where to begin learning about JavaScript touch events for web development. Any suggestions?

Seeking guidance on creating image galleries and content sliders that work with both touch and mouse events. Where should I begin exploring touch event implementation? I'm having difficulty locating official documentation. Are there any jQuery-suppo ...

Angular 4 after ejection, coupled with automated end-to-end testing using Protractor/Selenium setup

I am attempting to conduct end-to-end tests using Protractor/Selenium on an Angular 4 project that has been ejected. Here is my package.json: ... "scripts": { "pree2e": "webdriver-manager update --standalone false --gecko false --quiet node", "e2 ...

The date-fns parse function will retrieve the value from the previous day

When attempting to parse a date using the date-fns library, I am encountering an issue where the resulting date is one day prior. How can this be resolved in order to obtain the correct result? start = '2021-08-16' const parseStart = parse(start, ...

Check if the page has been loaded using Jquery

Can anyone share a helpful strategy for initiating a function in JavaScript that only begins once the entire page has finished loading? ...