i have textarea with text that is sperated with line break i want to loop this list in reverse order? so if i have text that loop like this
1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,2
1,1,1,1,1,1,1,3
1,1,1,1,1,1,1,4
1,1,1,1,1,1,1,5
it will read from 1,1,1,1,1,1,1,5 ... to .... 1,1,1,1,1,1,1,1 i know i can loop the text area like this :
$.each($('textarea[name=source]').val().split('\n'), function(e){
alert(this);
});
how can i convert it so it read the text in reverse order
Use .reverse()
and loop.
var myArray = $('textarea[name=source]').val().split('\n');
myArray.reverse();
$.each(myArray, function(){
alert(this);
});
you can use reverse()
directly instead of using a temporary variable to hold your array data.
$.each($('textarea[name=source]').val().split('\n').reverse(), function(e){
alert(this);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.