html
<textarea id="gps" name="gps"></textarea>
<button>Click</button>
jquery
$('button').click(function(){
var arrayOfLines = $('#gps').val().split('\n');
$.each(arrayOfLines, function(index, item) {
$this = $(this);
console.log($this);
});
});
I am trying to output each line individually so that I can use them later on but at the moment the above seems to split each line and then place each letter as an object
JSBin
You are placing a string into a jQuery object. Just use the item
instead:
$('button').click(() => {
var arrayOfLines = $('#gps').val().split('\n');
arrayOfLines.forEach(item => console.log(item));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<textarea id="gps" name="gps">28.73514, -147.42323
4.09974, 66.93197
49.11390, 48.85446</textarea>
<button>Click</button>
Inside .each loop line id 'item' object, not 'this'.
<textarea id="gps" name="gps"></textarea>
<button id="btn">Click</button>
$('#btn').click(function(){
var arrayOfLines = $('#gps').val().split('\n');
$.each(arrayOfLines, function(index, item) {
console.log('here is line:', item);
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With