javascript - Find the largest number in an array of alphanumeric string in Jquery -
i have array data below
var arr = [daaguva1, dagguva2, dagguva3, dagguva4, daggu5, dag6, dagguv7, dagg8, daggs9, dagguvati10];
i want highest number in array of string i.e. 10 . need number can auto increment number 11 . help?
if names match same structure (letters followed target number) - use regex strip out non-digit characters , parseint remaining portion yield number. set high score , iterate through array , compare stripped down numbers high value , if higher - set higest value that.
var arr = ['daaguva1', 'dagguva2', 'dagguva3', 'dagguva4', 'daggu5', 'dag6', 'dagguv7', 'dagg8', 'daggs9', 'dagguvati10']; var high=0; for(i=0; i<arr.length; i++){ var num = parseint(arr[i].replace(/\d+/g, '')); if(num > high){high = num}; } console.log('highest number is: ' + high); var nextnum = high +=1; console.log('next number be: '+ nextnum )
Comments
Post a Comment