What I am looking for remove white space from every line start and end. I am trying the code posted on this answer
var lines = $("textarea[name=f01]") .val().split(/\n/);
var texts = [];
for (var i=0; i < lines.length; i++) {
if (/\S/.test(lines[i])) {
texts.push($.trim(lines[i]));
}
}
var n = texts.toString().split(",").join("\n");
$("textarea[name=f01]") .val(n);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<textarea name="f01" id="40459045A">
आज शिद्दत से
दिल चाह रहा है,
बंद आँखें खोलूं तो
सामने तुम हो !!
</textarea>
But result is like this
I think when , at the line end, its creating new empty line in it. I want result like
आज शिद्दत से
दिल चाह रहा है,
बंद आँखें खोलूं तो
सामने तुम हो !!
Let me know what I am missing in this. Thanks!