having difficulty altering a string in EJS

After passing a JSON string to my EJS page, I noticed that it displays the string with inverted commas. To resolve this issue, I am looking for a way to eliminate the inverted comma's and convert the string to UPPERCASE. Does anyone know how to achieve this?

app.get('/ranking/:category', (req, res) => {
    var category = req.params.category;
    var allCategory = ['webDesigning', 'webDevelopment']
    if (category !== undefined) {
        for(var i = 0; i < allCategory.length; i++) {
            if (allCategory[i] === category) {
                res.render('ranking', { name: category })
            }
        }
    }else {
        res.render('404');
    }
})

Currently, in my EJS code, I am attempting to access the category as shown below.

<h1><%= JSON.stringify(name) %></h1>

The desired output should be:

Web Designing

Answer №1

Alright, name is considered a string in this case. You have the option to simply display it as is. If you decide to use JSON.stringify(name), the result will be "something". This represents the JSON version of the string.

Now, if your goal is to convert camelCase into separate words with each word starting with a capital letter, you can achieve this by following these steps:

const camelCaseToSeparate = (camelCased) => {
  const withAddedSpaces = camelCased.replace(/([A-Z])/g, ' $1');
  return withAddedSpaces.substr(0, 1).toUpperCase() + withAddedSpaces.substr(1);
};

console.log(camelCaseToSeparate('webDevelopment'));

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

Encountering difficulty in retrieving data from the JSON API, resulting in a reference error

Encountering a reference error while trying to access the formula one API at this link. The specific error pertains to the inability to access MRData. Despite using JSON Editor and confirming the correct pathway, I am still facing this issue. Please find ...

Create essential CSS for every .html page using Gulp

Recently, I came across a useful npm package recommended by Google for generating critical CSS: var critical = require('critical'); gulp.task('critical', function (cb) { critical.generate({ base: 'app/', ...

If I use npm install to update my packages, could that cause any conflicts with the code on the remote server?

As I navigate through the numerous issues, I stumbled upon the command npm ci that is supposed to not change the package-lock.json file. However, when I attempt to run npm ci, it fails: ERR! cipm can only install packages when your package.json and package ...

Error message: "Module not found" encountered while executing test case

I am a beginner in node and nightwatch and I have followed all the initial instructions from setting up node, npm, selenium standalone, starting the selenium driver. I also downloaded the chrome driver and placed it in the same directory. I created the con ...

Manipulating DropDownList Attributes in ASP.NET using JavaScript

I am facing an issue with populating a Dropdownlist control on my ASCX page. <asp:DropDownList ID="demoddl" runat="server" onchange="apply(this.options[this.selectedIndex].value,event)" onclick="borderColorChange(this.id, 'Click')" onblur="bo ...

"Optimize Your Data with PrimeNG's Table Filtering Feature

I'm currently working on implementing a filter table using PrimeNG, but I'm facing an issue with the JSON structure I receive, which has multiple nested levels. Here's an example: { "id": "123", "category": "nice", "place": { "ran ...

Tips on storing a blob (AJAX response) in a JSON file on your server, not on the user's computer

After researching extensively on creating a URL from or downloading a blob in a computer, I require a unique solution: (1) Save a blob in own server into a JSON file, (2) Optimize the way to update a database using the data stored in the JSON. My attemp ...

NodeJS and MongoDB are struggling with the slow loading and decompression of a lengthy collection of images

I have been experiencing performance issues with my nodeJS application and mongoDB database. After uploading data into the images database, my API is taking over 40 seconds to load data. Even when searching through the collection using limits or cursors, t ...

Properties around the globe with Express & Handlebars

Currently, I am utilizing Handlebars (specifically express3-handlebars) for templates and Passport for authentication in my NodeJS application. Everything is functioning smoothly, but I have been contemplating if there is a method to globally pass the req. ...

JavaScript encounters an unexpected identifier: Syntax Error

I encountered a syntax error while executing the code below: var userAnswer = prompt("Do you want to race Bieber on stage?") if userAnswer = ("yes") { console.log("You and Bieber start racing. It's neck and neck! You win by a shoelace!") } else { ...

Tips for retrieving newly inserted records from a bulk insert statement in SQL Server with Node.js

Currently working on a multi-row insert query for node-mssql, I have come to the conclusion that the bulk query is the most practical option. However, an issue arises as there is no way to retrieve the inserted rows. Considering that bulk is designed for ...

Exploring the intricacies of tracking transaction details using the Paypal API

I am currently working on implementing the PayPal API using the PayPal Node SDK for processing payments. I have successfully set up the checkout process, but I am facing some difficulty in checking transaction details as a seller (business account). I ha ...

Issues with implementation of map and swiper carousel functionality in JavaScript

I am trying to populate a Swiper slider carousel with images from an array of objects. However, when I use map in the fetch to generate the HTML img tag with the image data, it is not behaving as expected. All the images are displaying in the first div a ...

Sending a PHP variable to a modal using jQuery Ajax

I've encountered an issue with my jQuery ajax script. I'm struggling to pass a variable to the modal despite spending all weekend trying to debug it. Here is the link used to call the modal and the ID I want to pass: echo '<img src="./i ...

Determine the success of an SQL query in Node.js

I've created a basic API using nodejs to connect my Flutter app with a SQL Server database, but I have a question. How can I verify if the query was successful in order to return different results? I'm attempting an update after a successful in ...

Encountering issues with QR Scanner npm library when using Chrome browser

Utilizing the library https://github.com/felipenmoura/qr-code-scanner for QR code scanning poses a couple of challenges: When clicking the button to trigger, Google Chrome throws an error while the library functions properly on Safari. Uncaught (in promi ...

Issue with reinstalling NodeJS and NPM on Windows 10

As someone new to node.js and npm, I decided to try using the purgecss npm plugin. Unfortunately, during an attempt to update and upgrade my node, things went wrong. I downloaded and installed version 11.1, but now everything is broken and I can't ev ...

Add a border to the 'contenteditable' class in a Bootstrap table after it has been modified

Looking for help with JavaScript and jQuery! I have a script that creates an HTML table from a CSV file, using Bootstrap for styling. I want to add CSS or a border to a table cell after it has been edited, but my jQuery attempts haven't worked. Any su ...

Attempting to display the todo item in the form of <li>, however, the todo.name property is not

I am currently developing a task manager application and have encountered a puzzling issue: When I include the Todo component within the TodoList component and pass the todo item as a prop todo = {name: "ssss", status: false, id: 0.0289828650088 ...

Using the KnockOut js script tag does not result in proper application of data binding

Being new to knockout js, I found that the official documentation lacked a complete html file example. This led me to write my own script tags, which initially resulted in unexpected behavior of my html markups. Strangely enough, simply rearranging the pos ...