I want to filter the first paragraph from the course_description
object properties. I need only the first paragraph as highlighted in the screenshot. (a big rectangle)
var description = apiData[i].course_description;
console.log(description);
reshtm += '<div class="col-md-6">\
<a href="coursesdetails" class="well">\
<h1>'+apiData[i].course_name+'</h1>\
<p>'+apiData[i].course_description+'</p>\
</a>\
</div>';
You could try this:
var elem = document.createElement('DIV');
elem.innerHTML = apiData[i].course_description;
var result = elem.firstChild;
console.log(result);
PS: You might get the escaped characters in the result which you can later trim it off.
As your string format (SS) , you can do something like below
var description = apiData[i].course_description.split("\r")[0]; // get first para
console.log(description);
您可以使用截断功能像这里
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.