I'm facing an issue dealing with a JSON array. I have a name that provides me with the following formatted code:
nanorep.floatingWidget.$refs.core.conversationSession.entries
(11) [a, a, a, a, a, a, a, a, a, a, a]
0:a {id: 2, articleId: "1156688772", type: 2, html: "<div id="DIV_1" style="box-sizing:border-box;color…ionUI.enableUserInput() }</script></div></div>", text: "Fyll ut feltene under for å starte en chat: Alle f…tionSession.conversationUI.enableUserInput() }"}
1:a {id: 3, type: 5, date: 1529495789458, html: "", text: ""}
...
Do you know how to extract the text from `nanorep.floatingWidget.$refs.core.conversationSession.entries[2].text` up to `nanorep.floatingWidget.$refs.core.conversationSession.entries[12].text`? Additionally, I need to handle scenarios where the length of the array varies. Sometimes there will be 10 or even 2 data blocks present. I want to create a variable containing all the text from `nanorep.floatingWidget.$refs.core.conversationSession.entries[all lengths].text`, in plain text format with spaces between them.
I attempted this approach since I have intermediate knowledge in Javascript and JSON. Here's my code snippet, any improvements would be appreciated:
var i=2;
var history = nanorep.floatingWidget.$refs.core.conversationSession.entries.length;
while (i<history) {
printObject(nanorep.floatingWidget.$refs.core.conversationSession.entries[i].text);
}
After solving one problem, I encountered another challenge—converting dots to new lines. The converted string appeared as follows:
jeg vil si opp avtalen min med fjellinjen hvordan gjør det,Husk å ta brikken ut av bilen [...]
hvordan får jeg tilbake depositumet på bombrikken,Du får tilbake depositumet når [...]
My issue lies in converting dots to new lines using:
chatHistory2 = historyText.toString();
chatHistory = chatHistory2.replace(/./gi, /<br>/); and
chatHistory = chatHistory2.replace(/./gi, /\n/);
I haven't been successful with these attempts. How can I correctly make each dot result in a new line?