[英]I am trying to split the text into paragraphs, it is splitting on commas instead of new line or paragraph using javascript
I am new to Javascript. 我是Java语言的新手。 I am trying to split the text into paragraphs using split method using Javascript.
我正在尝试使用Javascript使用split方法将文本拆分为段落。 The data is splitting on commas instead of new line or paragraph as shown below.
数据按逗号分割,而不是如下所示的新行或段落。
I am giving below input in DB: Math & English &Science
我在数据库中输入以下内容:
Math & English &Science
Output coming: Math,English,Science
输出结果:
Math,English,Science
var subjects;
var subject;
for (var i = 0; i < tabList.length; i++) {
for (var j = 0; j < responseText.length; j++) {
subjects = responseText[j].name;
subject = subjects.split("&");
console.log(subject);
var Obj = {
projectName: responseText[j].name,
projectDescription: subject,
currentStatus: responseText[j].rollno
}
Expected Output: 预期产量:
Math
English
Science
Could you please help me to resolve my issue. 您能帮我解决我的问题吗?
You probably need to do: 您可能需要做:
subject = subjects.replace(/&/g, '<br>');
not split
不
split
When you're displaying the data, put <br>
between each element of the array. 当显示数据时,将
<br>
放在数组的每个元素之间。
subjects = "Math & English &Science"; subject = subjects.split("&"); console.log(subject); var Obj = { projectName: "Name", projectDescription: subject, currentStatus: "Complete" } document.getElementById("project").innerHTML = Obj.projectDescription.join("<br>");
Project description: <div id="project"> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.