Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
54
rated 0 times [  55] [ 1]  / answers: 1 / hits: 25155  / 6 Years ago, mon, august 13, 2018, 12:00:00

I have an array that i transformed it into text with array-to-txt module.



Instead i wanted it transformed to a big string, but i wanted a newline after every index of the array (the afforementioned module does this automatically).



So i wrote this:



result.toString();
result = result.split(,).join(n);


Where result is the array. It didn't work, so then i tried this:



result.toString();
var output = result.split(,).join(n);


Still i get the TypeError: result.split is not a function error.


More From » node.js

 Answers
59

The problem you have is result.toString() doesn't modify the original array...it only returns a string.



You would need something like:



var str = result.toString()
var output= str.split(',').join('n');


However there is no need to convert to string and immediately back to array when all you really need is:



var output = result.join('n')

[#53739] Thursday, August 9, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
neildrews

Total Points: 166
Total Questions: 103
Total Answers: 85

Location: Moldova
Member since Sat, Aug 6, 2022
2 Years ago
neildrews questions
Fri, Feb 18, 22, 00:00, 2 Years ago
Tue, Oct 12, 21, 00:00, 3 Years ago
Tue, Mar 23, 21, 00:00, 3 Years ago
Sun, Aug 16, 20, 00:00, 4 Years ago
;