How to insert an element INTO a JSON array using JavaScript

I'm having an issue with the way a line is displayed on my screen:

Would you like to pay €xx to POS_ID Latte  X 1....€2.50-Salad  X 1....€4.00-Wrap  X 1....€4.50-Coffee X 2....€3.00-

My desired format is as follows:

Would you like to pay €xx to POS_ID "Latte  X 1....€2.50- Salad  X 1....€4.00- Wrap  X 1....€4.50- Coffee X 2....€3.00-".

This message is generated by parsing the JSON below:

{"action":"POS_clear","id":"POS_ID","paramater":"14.00", "purchaseList":"Latte  X 1....€2.50-Salad  X 1....€4.00-Wrap  X 1....€4.50-Coffee X 2....€3.00-", "ClientID":"1234"}

Initially, I used /n instead of - but faced issues with parsing the JSON (due to the /). I then replaced the slash with a dash and considered using splicing. However, I am unsure of how to proceed. Any assistance would be greatly appreciated!

Answer №1

When you see them appearing on an HTML page, consider substituting the dashes with the HTML tag <br>.

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

Issues with looping in Internet Explorer 8

Hey, I'm having an issue with this JavaScript function: function test(){ var count = 0; var date1 = $('#alternatestartdate').val(); var date2 = $('#alternateenddate').val(); ...

Is it possible to halt the execution of a code or skip the remainder of it if a specific condition is met using jQuery?

Is it possible to prevent a code from completing or skipping the remaining parts based on a specific condition? For example, var stopCode = false; if (stopCode === true) break; .... .... blah blah blah the remaining part of the code .... ... Can this b ...

One of the challenges faced with using AngularJS is that it can often

I have a piece of code that is functioning correctly: angular.module('foo', []).config( function($locationProvider) { $locationProvider.html5Mode(true); } ); However, when the code is minified, it gets compressed and looks like this: a ...

A guide on choosing a custom button color and automatically reverting to its original color when another button is clicked

I have a collection of 24 buttons, all in a dark grey (#333333) shade. Whenever I click on one of the buttons, it changes to a vibrant blue color (#0099ff), which is functioning correctly. However, when I proceed to click on another button, the previous ...

Angular does not seem to be triggering $watch for changes in arrays

Trying to activate a $watch function after a delay in Angular: Controller Information .controller('MyCtrl', ['$scope', function ($scope) { $scope.chickens = ["Jim", "Joe", "Fred"]; $scope.chickens.push("Steve"); setTimeou ...

Displaying numbers as characters in AngularJS: Use $index variable

Within my ng-repeat, I have two <li> tags repeating a specific number of times. The $index is being used to determine the position of each <li>. You can view a sample on this fiddle: http://jsfiddle.net/sh0ber/cHQLH However, I would like one ...

What could be the reason that step 3 of the AngularJS Tutorial is not functioning correctly?

During Step 3 of the AngularJS Tutorial, an additional e2e test is recommended to enhance the example: it('should display the current filter value within an element with id "status"', function() { expect(element('#status').text() ...

Is it possible to convert a JSON string to a Custom Object when minifyEnabled is set to true?

My Android application is utilizing an API to retrieve a JSON string and then attempting to convert it into a custom object. It functions properly when minifyEnabled is set to false, but when switched to true for creating an APK, I noticed that Gson is una ...

Retrieve information from a URL using an Express API

Every 45 minutes, my API receives a request: GET http://MyHost/mediciones/sigfox_libelium/{device}/{data}/{time}/{customData#trama} I need to extract {device}, {data}, {time}, and {customData#trama} from the URL and store them in separate variables. This ...

Tips on sending form data, including a file, to Ajax using the onclick() method

My Modal Includes a Form: <div class="modal fade bs-example-modal-lg" id="myMODALTWO" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" id="form-content"> <div class="modal-dialog modal-lg" role="document"> ...

Using jQuery to update a specific item in a list

My current project involves developing an Image Gallery app. It uses <img> tags within li elements. The code snippet is as follows: var $slideR_wrap = $(".slideRoller_wrapper"); var $slidesRoller = $slideR_wrap.find(".slidesRoller"); var $slideR ...

Node.js Azure Functions: My route parameters are not included in context.bindingData as the documentation implies

I'm currently working on a function that needs to retrieve 2 route parameters (first required, second optional), but I'm encountering some difficulties despite following the Documentation provided. I am specifically referring to this set of inst ...

What are the steps to manipulate the data within an EJS file after passing an array through Node.js as an object?

I'm currently developing a simple calendar application using Node.js and ejs. I am working on passing an array of months through express to my ejs file, with the goal of being able to cycle through each month by clicking the next button. How can I imp ...

Guide to displaying PHP output in a format suitable for plotting

I'm currently working on plotting PHP output from a MySQL database using . The desired format for the output should look like this - var data = [ { x: ['giraffes', 'orangutans', 'monkeys'], y: [20, 14, 23], ...

Accessing data from an external domain via JSON file retrieval

It's been a while since I've worked with JSON, so I'm a bit rusty on the process of requesting data from another domain or web server. <?php header('Access-Control-Allow-Origin: *'); if(!empty($_GET['file'])){ ?> ...

How to dynamically load a file based on the chosen option value in React

Two select textboxes on my page are named Choose City and Choose District. I also have some files related to cities and districts: // cities.js const cities = { "01": { "name": "City 1", "code": "01" }, ...

Using Cheerio with a Node.js bot

I am currently utilizing Cheerio to extract information from web pages in my .js files. However, I would like these files to automatically restart every 1 day to check for any new data. Instead of using setTimeout, which may not be efficient for managing ...

Utilizing fluent-ffmpeg in nodejs and express to effortlessly download a video

I've been recently tackling a side project that involves downloading videos from Reddit. The tricky part is that the video and audio are stored in separate files, requiring me to merge them before being able to download them onto the client's dev ...

Creating a new database row dynamically with PHP, JavaScript, and AJAX

There is a button that triggers a popup box with a textfield when clicked. Once something is entered in the textfield and the "Add" button is clicked, it should be added to the database. Currently, upon clicking "Add", data is inserted into the DB but it ...

In Cypress, I am trying to specifically choose only numerical values from a dropdown menu. However, the list contains a mix of alphanumeric and numeric values

Looking to streamline: This is my code: cy.get('[role=presentation]') cy.get('[role=row]').find('td') .get('[role=gridcell]').eq(9).click().wait(2000) cy.get('[role=listbox]').get('[role=option]& ...