sort string mixed with numbers javascript

Solutions on MaxInterview for sort string mixed with numbers javascript by the best coders in the world

showing results for - "sort string mixed with numbers javascript"
Vincent
03 Nov 2020
1function sortNumber(a, b) {
2  return a - b;
3}
4Arr.sort(sortNumber);
Niko
21 Sep 2016
1var reA = /[^a-zA-Z]/g;
2var reN = /[^0-9]/g;
3
4function sortAlphaNum(a, b) {
5  var aA = a.replace(reA, "");
6  var bA = b.replace(reA, "");
7  if (aA === bA) {
8    var aN = parseInt(a.replace(reN, ""), 10);
9    var bN = parseInt(b.replace(reN, ""), 10);
10    return aN === bN ? 0 : aN > bN ? 1 : -1;
11  } else {
12    return aA > bA ? 1 : -1;
13  }
14}
15console.log(
16["A1", "A10", "A11", "A12", "A2", "A3", "A4", "B10", "B2", "F1", "F12", "F3"].sort(sortAlphaNum)
17)
Leo
22 Jan 2018
1const sortAlphaNum = (a, b) => a.localeCompare(b, 'en', { numeric: true })
2console.log(['A1', 'A10', 'A11', 'A12', 'A2', 'A3', 'A4', 'B10', 'B2', 'F1', 'F12', 'F3'].sort(sortAlphaNum))
queries leading to this page
how to sort numbers array in javascriptjs sort array by numberarray sort js by integersort array javascript numberssort array generated numbers javascripthow to sort numbers in a string jshow to sort array of numbers in javascripthow to sort an array numerically in javascriptsort array values ascending javascriptsort by highest number javascriptsort list of list of numbers in javascriptjs sort array of numberssort array numerically javascripthow to sort an number array in java scriptorder array of numbers javascriptsort number javascriptsort an integer array in javascriptsort array of numbers in javascriptsort int array javascriptsorting all integers javascriptjavascript not sorting comma integersfow to sort a number array in javascriptarray in javascript sortierensort an array of numbers in decreasing order in javascripthow to arrange numbers in ascending order using array in javascriptsort array by number javascriptsort numbers in javascripthow sort list of number in jssort numbers in array javascript descendingsort javascript array of numbersjs sort function with numbersarray sort by number in node jssort js does not sort numbersjavascript sort array of intregerssort javascript number arrayarray sort for numberssort array of arrays by numberjavascript sort numbers in array containing 0javascript sort array of integerssort number of array in jssort numbers javascriptjs sort array integerssorting even numbers out of an array in javascriptsort list of numbers javascriptsort phone numbers array jssort number string javascriptsort numbers in array and add in javascriptsort number javascriptjavascript integer array sortjavascript sort int arraysort for numbers in jsnumeric sorting in javascriptsort list by number javascripthow to sort a number in javascriptsort ascending javascript returning a numberjavascript sort array numbers descjs sort method numbersjavascript sort string with numbersjs array sort by numberjavascript sort string numbersorder array numbers javascriptsort string with numbers jsprint numbers in descending order javascriptsort by number javascriptjavascript sort array of numbers ascendingsort numbers array javascriptorder by list of numbers in jsnumber sort in javascriptsort from lowest to highest numbers javascriptorder numbers with arrays javascriptsort an array of numbers asc javascriptsort number s jsfind number in a string and sort array by the numbers jssort numbers in ascending order jshow to order numbers in javascriptjs sort array of integerssort numbers from lowest to highest javascriptorder numbers in jsjavascript sort numbers in an arrayhow to sort string with numbers in javascriptjs sort intsort string with numbers javascriptjs why does array sort numbersjavascript sort integer arraysort numbers in jsorder an array of numbers javascriptjs sort array by number itemsort array nums javascriptjs sort array string numbersarrange numbers in ascending order in array javascript sort javascript numbersjavascript function sort number and stringsort by number values js javascript sort numbersnumber sort method javascripthow sort string and numbers javascripthow to sort numbers in order javascriptsort array of numberssort numbers javascri 5bpthow to sort a number array in javascriptjavascript sort an array of integerssort an array of numbershow to sort number in array javascriptsort array by number valuejavascript sort numbers in ascending orderhow to do sort in javascript mathhow to sort array of number in jssort numbers in array jssort 3 numbers javascriptsort numeric array in javascriptsorting of numbers in javascriptjavascript sort by numberusing sort in a function to sort an array of numbers javascriptsort numbers in array nodejshigest to lowest number sorting in array javascriptsort list of numbers in array javascriptsort numbers ascending javascriptsort an array based on numbersjavascript sort non numeric arrayhow to sort numbers in ascending order in javascriptjavascript sort numbers descendingcan i use javascript to sort array of array of numberssort numbers in arraysort an array of num javascriptjavascript array sort intsort by numbers in the string of array javascriptjavascript sort numbers in arraysort by number jsjs sort numbers in numeric ordersort int array nodejssort array based on number in it jsjs sort a list by numberjs numeric sortsort string alphabetically js but also handle numberssort integer array javascriptjavascript array of ascending numberssort numbers jsarray sort method javascript numbershow to sort 3 numbers in javascriptsort numbers highest to lowest javascriptsort an array numerically javascripthow to sort numbers in an array in ascending order javascriptsort integer array jssort array of integers in javascriptjavascript sort array of numberssorting numbers in an array jsjavascript sort integershow to sort numbers in arrayjs sort numbershow to sort out javasxript numbers array elements desc 3fsort string array with numbers jssort javascript array with given number sort numbers in an arraysort number in jssorting integer array in javascriptjs sort numeric arraysort array numbers javascriptjavascript sort array numberssort numbers in array javascriptsort array of int jsjs sort numbers and get lowest and highesthow to sort numbers in a matrix array in jssort numbers numerical order jssort array change numbers in javascriptsort numeric in jsjavascript sort array by integer valuejavascript sort numberjs integers sort sort int array jshow to sort numbers in javascript arrayarray order numbers jssort integers ascending javascriptjavascript sorting the numbershow to sort a numerical array in javascriptjs sort array numericallyarray sort numbersnumeric sort in jsjs array sort numberhow to put in order numbers in an array jsjs number array sortsorting strings with numbers javascriptsort an array of number javascriptsort number array jsjavascript sort on numberjavascript how to sort by numbersort a number array javascripthow to sort al the values in the array in ascending order in javascriptnumbers sort javascriptsort string mixed with numbers javascriptjavascript sorting array of numbersjs sort array inthow to sort a list of numbers using jsjs sort string with number arraysorting integers in javascriotsort number arraysort number array javascripthow to sort numbers in jslist js sort numbershow to sort a list of numbers in javascripthow to sort 5 numbers in jssort the numbers the arraysort a set of numbers javascriptnode sort numberssort array of numbers in ascending order in javascriptfilter to sort numbers javascripthow to sort list in javascript according to number in javascriptsort array in numbershow to sort integer array in javascriptsort a number inside an array javascripthow to sort numbers in array in js with a loop js sort numbers ascwhy is a b returned in array sort numbers jsjavascript sort by numberical valuehow to sort numbers in string javascriptjs sort array numbersortarray numbers javascriptfunction to sort array numbers in javascript js sort int arrayhow to sort a number in an array in jsarrays sort numbersjs sort array of arrays of numbersnumber sorting jssorting numbers array in javascriptsorting numbers in javascripthow to sort number array in javascriptsort array by numbersorting array of numbers in javascriptsort list of arrays with numbers javascriptsort number jssort array elements by integer javascriptjs sort number arraysort list of arrays with numbersjavascript sort integers jshow to sort number array javascriptjavascript sort array of numbers not workinghow to sort an array with numeric values in ascending order in jsjs sort 28 29 numbersjavascript sort ascending numberssort array of number in javscriptsort integer array in javascriptsort by array of numberssort numbers from lowest to highes javascriptjavascript sort numbers stringsort values array jsnumber array sort in javascriptsort number in array javascriptjs sort integer arrayarray sort integer jssort strings and numbers javscripthow to sort number using javascripthow to make an array sort numbers in javascripthow to sort a number in node jsarr sort numbershow to sort int array javascripthow to sort numbers in javascriptsort array of numbers javascriptjs sort number arraysort array by numbetsort integer array in jssort an array of numbers javascriptsorting with numbers and letter jsjavascript sort list of integersjavascript default array sort of numbershow to sort a set of numbers javascriptjavascript sorting numbersarrange one array in order of number array in javascriptjavascript order array of numbercreate ascending number array javascripthow to sort numbers in ascending order javascriptjs order array numberssort numbers in ascending order javascripthow to sort numericaplha values in array in javascriptnumeric sort in javascripthow to sort numbers by the largest jsfunction sort numbers into new arraysort array of numbers jsjs sort strings as numberssort an array of number in javascriptjs sort by numberssort 3 numbers jssort array by value javascriptjavascript array element numbers ascending orderhow can i sort numbers in jsarray number sort javascriptsorting numbers in array javascripthow to sort an array of integers jsjavascript number sortjavascript sort array string numberssort an array in ascending order by values themselves javascripthow to sort numeric array in javascriptsort numbers js with inputjavascript sort numbers in array 5b9 2c8 2c7 2c0 5dsort an array javascriptjavascript order list by numbersort array string numbers javascriptsort array by number jssort numbers in array javascript without using functionhow to sort list in javascript according to numbersort numbers array jssort numbers using if jsnumeric sort javascriptsort numbers in aray by valuesort and array of integers in javascriptaray sort with numbersjs order array of numbersjavascript sort array by value numberhow to sort number in javascriptsort numbers javascript arrayjs sort on numbernumeric sort array javascriptarrange numbers in ascending order jsjavascript create an array of sorted numbersnumber sort jsnumber sort javascriptbuble sort array of numbers javascriptsorting of number arrayjavascript sort number listsort list of integers javascriptjavascript sort array numericallysort array based on number javascriptarrange an array of integers in ascending order javascriptsort js numberssort integers in array javascriptjavascript sort by numhow to sort numbers in array in javascriptorder numbers in a arrayhow to sort number jshow sorting works in javascript for numbershow to sort an array in ascending order javascriptsort integers array jsjavascript array sort but not 1 numbersort string mixed with numbers javascript