Reveal the array on the frontend in a row each time using Javascript

My array contains the following items:

let array=["First", "Second"]

I want to display each item on a separate line (without commas), like this:

First

Second

I attempted splitting the array using:

let data.split("\n")

However, the output was:

["First,Second"]

How can I properly format and display each item from the array without the comma?

Answer №1

To merge the data that is already separated, there is no need to split it further. Instead, use the data.join() method.

When you specify a parameter for data.join(), that parameter will be inserted between each piece of data.

In this situation, you could use data.join(\n). (Where \n represents a new line character).

Alternatively, you can utilize data.join(<br/>) to display your text in plain html. (Here, <br/> refers to an html break tag).

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

unable to retrieve the response from a POST request sent to a node server

Currently in the process of learning how to utilize node and express, I have embarked on creating a sample website that incorporates both along with the Google translate API. The goal is to explore the numerous features offered by these technologies. Unfor ...

JavaScript - Insert rows within the tbody element by adding them after the opening tbody tag. The new rows should be

Having trouble adding rows in JavaScript. The code is functioning correctly, but the new rows are appearing after the tbody tag instead of inside it. Here's a snippet of the code: function deleteRow(row) { var i = row.parentNode.parentNode.rowIn ...

Show picture during the process of loading an external webpage

Utilizing a script to load an external page (external meaning a page within my website) inside a div. Loading the page takes time, so I want to display an image until the page is fully loaded. JAVASCRIPT function HideLoader() { $('#loader' ...

How to fix the Uncaught TypeError: Unable to access the 'open' property of an undefined value in the AppBar + Drawer component with ReactJS and Material-UI?

I'm currently working on implementing the navigation feature in my app using Material-UI framework. I want the default hamburger icon on the left side of the AppBar to open the Drawer component when clicked. However, I keep encountering an error that ...

Add elements to the array, extract elements from the array

tag, I am currently facing a challenge with transferring multiple attributes from SharePoint list items into an array (only selected items in a view) and then passing that array to a function where I can extract and use these attributes to create new list ...

There was an issue with the JSON parsing process due to an unexpected token 'o' at position

Trying to extract titles from a JSON object for a specific feature, here's an example of the JSON structure: [ { "title": "Example 1", "url": "http:\/\/www.example1.com\/" }, { "title": "Example 2", "url": "http:& ...

Extract the sub-element within a parent element using Vue event handling

Objective The main aim is to add a class to the dropdown element .menu-item-dropdown whenever the user clicks on the .menu-item element. Issue Currently, when clicking on the .menu-item element, the returned value from the console.log inside the showMob ...

Is there a way to modify the HTTP response code of a PHP page based on a specific condition determined by the response of an AJAX call in jQuery?

When calling a page on my search page using ajax, I receive JSON data. I am trying to set the HTTP response code of the page based on the results. If the keyword is found, I want to keep the default response code. However, if it is not found, I want to cha ...

The Node.js engine isn't updating to support compatibility with Firebase functions

Encountered First Failure Below is the content of package.json "engines": { "node": "8.0.0" }, Error: The engines field in the functions directory's package.json is unsupported. You can choose from: {&quo ...

Display a loading screen with a progress bar using React Native Expo

Currently, I am diving into the world of React Native and honing my skills using Expo. One of the tasks I've tackled is creating a loading screen for my app using npm react-native-progress. However, I'm curious if there is a way to replace the de ...

Unable to retrieve a return value from an asynchronous waterfall function within a node module

A custom node module that utilizes async waterfall is working properly when run independently, but the AJAX callback does not receive the return value. //Node module var boilerplateFn = function(params){ async.waterfall([ function(callback){ ...

What steps should I take to ensure that the getElementsbyName function works properly on both Internet Explorer and Firefox browsers

Encountering a JavaScript error in IE but not in FF ("document.getelementsbyname(...).0.innerhtml is null or not an object": var oldVal = parseInt(document.getElementsByName("outSL")[0].innerHTML); //value pulled from the database Here is the asp.net c ...

Leveraging JavaScript Fetch() and formData() for Database Updates

As I delve into my JavaScript project, utilizing the fetch() method, I find myself facing a puzzling situation. Despite having a grasp on the basics of fetch and formData, the code in question appears needlessly complex for its intended purpose, leaving me ...

Display a loading message using jQuery Dialog when the page is loading

I have a button that triggers a jQuery Dialog box to open. $( "#dialog" ).dialog({ autoOpen: false, title: 'Contract', height: 450, width:1100, modal:true, resizable: true }); $( ".btnSend" ).click(function() { var id=$(this).a ...

How can I expand all primary accordions while keeping secondary accordions collapsed?

I have a main accordion with nested accordions within each item. My goal is to only expand the main level accordions when clicking the button, without opening the nested ones. I want to open all "Groups" accordions while keeping the sub-accordions labeled ...

Typescript: Error encountered. Invalid input: Non-string value provided to `ts.resolveTypeReferenceDirective`

A while back, I developed an npm command line application that was working perfectly fine. However, after a recent update due to changes in TypeScript versions over time, I encountered an error when trying to run the package. The error message I received w ...

How to use Yii2 to trigger a controller action from a view and effectively debug the

Within a data grid view, there is a text input field where I intend to trigger a controller function when the field is updated. To achieve this, I have embedded a script in my form and set up a controller function. $this->registerJs( "$('#prod ...

What steps can be taken to solve the JavaScript error provided below?

My objective is to create a new variable called theRightSide that points to the right side div. var theRightSide = document.getElementById("rightSide"); Once all the images are added to the leftSide div, I need to use cloneNode(true) to copy the left ...

What is the best way to transfer values from an iterated object in HTML to a component in Angular 2/4?

My Angular2/4 app allows for file uploads to S3. The setup is such that when a user uploads a file, it will be stored in an S3 bucket. Once uploaded, the user will be shown the list of files they have uploaded. In case they upload the wrong file by mistake ...

Ways to eliminate an item from an array when the value of the object is not present

I am facing an issue with removing objects from an array that do not contain the data object. I have attempted to use the filter method but have not been successful. results.filter(obj => obj.data === undefined) results = [ {id: 1, location: 'a&a ...