Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
54
rated 0 times [  55] [ 1]  / answers: 1 / hits: 16502  / 8 Years ago, thu, september 8, 2016, 12:00:00

I've been developing a website using the YouTube A.P.I.



Within the description tag in the JSON file are line breaks n



I need to convert these tags to HTML format



VideoDescriptions.push(item.snippet.description);

[Example descriptionnPlease click the link, Another example descriptionnMore info]


Edit:



This question is NOT a duplicate of the linked article because:




  • It's using the YouTube API to retrieve data

  • It's necessary to edit from an array rather than the string (as
    described in the article)

  • The answers in either question could lead to different results and
    may not apply


More From » html

 Answers
42

You can simply use string replace in javascript:




var items = [Example descriptionnPlease click the linknn, Another example descriptionnMore info];
console.clear();


var changed = items.map(i => i.replace(/n/g, '<br />')).join('');
var div = document.querySelector(#test);
div.innerHTML = changed;

<div id=test></div>




[#60779] Monday, September 5, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
arthur

Total Points: 729
Total Questions: 107
Total Answers: 109

Location: China
Member since Mon, Aug 22, 2022
2 Years ago
;