What is the origin of the trailing commas seen in these radio button choices?

After closely examining my radio buttons, I noticed a strange issue - there is an unexpected trailing comma after each option. Strangely, I did not add these commas in the template and I cannot figure out where they are coming from.

Initially, I suspected it could be due to a script, but even after isolating the problem, the issue continues to persist.

const options = [
        "User-friendly",
        "Interactive",
        "Accessible",
        "Other (Specify below)"
      ];
      const template = `
    <div class="question-title">sdjhaskjdhakjs</div>
    <div class="question-options">${options?.map((option, i) => {
      return `
      <div class="question-option">
        <input class="${"id"}-feedback-question-option" type="radio" id="${"id"}-${option}" name="option" value="${option}" ${
        options.length === i - 1 ? "checked" : ""
      } />
        <label for="${"id"}-${option}">${option}</label>
      </div>`;
    })}</div>
  `;
 
 document.getElementById("app").innerHTML = template;
.question-title {
      position: relative;
      height: 40px;      
      display: flex;
      align-items: center;
      justify-content: center;
      font-weight: normal;
      font-size: 16px;
    }

    .question-options {
      position: relative;
      display: flex;
      align-items: center;
      justify-content: center;
      font-weight: normal;
      font-size: 12px;
      gap: 10px;
      flex-warp: warp;
    }

    .question-option {
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 5px;
    }

    .question-option>label {
      margin-bottom: unset;
    }

    input[type=radio]::after {
      content: '';
    }
<!DOCTYPE html>
<html>
  <head>
    <title>Parcel Sandbox</title>
    <meta charset="UTF-8" />
  </head>

  <body>
    <div id="app"></div>
  </body>
</html>

Answer №1

When arrays are converted to strings, they are automatically joined with ,

To avoid this behavior, you can use .join('')

const options = [
  "Easy to use",
  "Loading",
  "Fast",
  "Others (Mention below)"
];
const template = `
    <div class="question-title">sdjhaskjdhakjs</div>
    <div class="question-options">${options?.map((option, i) => {
      return `
      <div class="question-option">
        <input class="${"id"}-feedback-question-option" type="radio" id="${"id"}-${option}" name="option" value="${option}" ${
        options.length === i - 1 ? "checked" : ""
      } />
        <label for="${"id"}-${option}">${option}</label>
      </div>`;
    }).join('')}</div>
  `;

document.getElementById("app").innerHTML = template;
.question-title {
  position: relative;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: normal;
  font-size: 16px;
}

.question-options {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: normal;
  font-size: 12px;
  gap: 10px;
  flex-warp: warp;
}

.question-option {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.question-option>label {
  margin-bottom: unset;
}

input[type=radio]::after {
  content: '';
}
<!DOCTYPE html>
<html>

<head>
  <title>Parcel Sandbox</title>
  <meta charset="UTF-8" />
</head>

<body>
  <div id="app"></div>
</body>

</html>

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

Vertical centering menu adjustment

Can anyone help me with centering an image on my website? I've tried the following code: top: 50%; -webkit-transform: translateY(-50%); -ms-transform: translateY(-50%); transform: translateY(-50%); You can see what's happening on my site here: ...

Is there a way to ensure a function is only executed once whenever the page is refreshed?

I have the following code snippet: function myfunc () { alert('executed'); } $('.classname').on('click' function () { myfunc(); }); I am trying to ensure that myfunc is only executed once. I don't want it to ru ...

Angular: promptly exit out of ngClick event handler

I have a selection menu on my webpage that is essentially an unordered list, with each item in the menu formatted like this: <li ng-click='doCalc(5)'>Five</li> The doCalc function that is triggered by clicking on these items may tak ...

Issue with passing JSON data to a PHP file using CURL

I am currently working on a project that involves sending exam data with the exam-name and the selected number of questions from a list. Here is the project architecture I am following: To send JSON via AJAX to my make_exam.php file The questions.php fil ...

Troubleshooting jQuery click event listeners and AJAX requests: Issue with second listener not functioning properly

There are two click listeners implemented on a page, one for a sub-navigation menu (which dynamically changes the list items in the menu) and another for a main menu (which dynamically changes the content in another section). <nav class="sub-nav"> ...

Combine several JSON files into a single file

After spending countless hours searching on Google, I finally gathered the courage to ask my question here. I have several json files. localhost/feed01.json localhost/feed02.json localhost/feed03.json All of the json file structures are similar to this ...

Restricting the time frame in HTML 5

My form includes an input field with the type date <input type="date" id="datepick" name="mybirthday" placeholder="Birthdate(MM/DD/YYYY)" /> I am looking to restrict the date range that users can select. I specifically do not want users to be able ...

Parsing JSON data with new line characters

What is the reason behind being unable to parse a json with a \n character in javascript? JSON.parse('{"x": "\n"}') Surprisingly, when you use JSON.parse(JSON.stringify({"x" : "\n"})), it works perfectly fine. indicates that {" ...

Mastering the Vue 3 Composition API: A guide to efficiently utilizing it across multiple Vue instances spread across different files

tl;dr What is the best way to import Vue3 in a base Javascript file and then utilize Vue's composition API in subsequent standalone files that will be loaded after the base file? I incorporate Vue to improve user interactions on specific pages like t ...

Switch out a section of a hyperlink with jQuery

I am currently working with an 'iframe' that loads up a page containing multiple external links. My goal is to modify these links so that they redirect to 'Youtube' instead. For instance, one of the links on the page appears as follows: ...

I'm attempting to access CapCut through the site with Selenium, but I'm having trouble clicking on a specific button

My goal is to click on a specific button with the following code: <button class="lv-btn lv-btn-primary lv-btn-size-default lv-btn-shape-square lv_sign_in_panel_wide-primary-button" type="button"><span>Continue</span>&l ...

Is it advisable for a JavaScript web application to incorporate a different server-side language?

Looking to dive into web application development, I find myself unimpressed with the available frameworks for Java. While considering using PHP as an alternative server-side language, I am hesitant due to the learning curve involved. This has led me to ex ...

Tips on creating hyperlinks for each database entityCreating hyperlinks to individual database entities

I have a database table with three columns and four rows. I am looking to add hyperlinks to each entity in the third column of the table and then display the output. When attempting to print the array values, I used the following code: echo "<td>", ...

Repeating calls to the init() function within an AngularJS controller

Encountering an issue while developing an angularjs application. I have set up a controller and bound it in routeProvider with a function to initialize values like so: angular.module('app.Login', ['app.rpc','ngRoute']) ...

What is the best way to resize a div to fit its content if 'clear:both' and 'float:left' are not working as desired?

I've been struggling to find a solution for an issue with my HTML. I have three 'divs' that need to display different information in their own line, enclosed in a parent element with a centered border. Despite trying solutions like inline-bl ...

When trying to apply styles using ng-style attribute with jQuery, Angular does not seem to

Check out this plunker showcasing the issue : http://plnkr.co/edit/1ceWH9o2WNVnUUoWE6Gm Take a look at the code : var app = angular.module('myApp', []); app.controller('myCtrl', function($scope) { console.log('yeah'); ...

Using JavaScript to inject PHP variables into multiple <span> elements

I have been searching for a similar query without any luck. Currently, I am attempting to display the number of Twitter/Facebook/RSS followers within a <span>....</span> in my sidebar. To retrieve the follower counts, I am using some PHP scrip ...

the ability to utilize the @click glyphicon signal

In this scenario, as soon as I type something into the input field, the glyphicon-remove icon will appear. Upon clicking on it, the intention is for it to reset the search input. Below is the code snippet: <div class="form-group has-feedback has-feedb ...

Cannot adjust dimensions of Chart.js

Struggling to resize chart.js on an HTML page. Have attempted various methods like adjusting the canvas parameters, defining section and div tags, explicitly setting height and width in <style>, as well as using {responsive: true, maintainAspectRatio ...

I encountered a 404 Error message while attempting to access a specific express route

My Angular CLI generated app is running with an Express.js and MongoDB server. After running npm start, I can access http://localhost:3000, which routes to my homepage. The other links on the navbar work well to control routes, e.g., http://localhost:3000/ ...