This article analyzes the implementation method of JS returning only array types. Share it for your reference, as follows:
Implementation effect is as follows: js123ldka78sdasfgr653 => [123,78,653]
General practice
analyze:
1. Each character of the loop string is selected and spliced together by numbers. It is not numbers. Just spell a comma for the empty string.
2. Convert each bit of the new string into an array, traverse it again, pick out the existing ones, and get the result
var str="js123ldka78sdasfgr653"; var new_str=""; var arr=[]; var arr2=[]; for(var i=0;i<;i++){ var code=(i).charCodeAt(); if(code>=48&&code<=57){ new_str+=(i); } else{ new_str+=","; } } arr=new_str.split(","); // Without writing separators, the entire string is loaded into the arrayfor(var i=0;i<;i++){ if(arr[i]){ (arr[i]); } } alert(arr2);
Regular:
var str="js123ldka78sdasfgr653"; var re=/\d+/g; str=(re); alert(str);
For more information about JavaScript, readers who are interested in reading this site's special topic:Summary of JavaScript array operation skills》、《Summary of JavaScript sorting algorithm》、《JavaScript traversal algorithm and skills summary》、《Summary of JavaScript mathematical operations usage》、《Summary of JavaScript data structure and algorithm techniques》、《Summary of JavaScript search algorithm skills"and"Summary of JavaScript Errors and Debugging Skills》
I hope this article will be helpful to everyone's JavaScript programming.