-
-
Save NKid/e37cfbfaa47f22c71f27 to your computer and use it in GitHub Desktop.
遍歷字串每個字元
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Method 1 | |
var str = "132ada5d6g3j"; | |
var match = str.match(/\d/g, str); | |
var arr = []; | |
var j; | |
for(var i = 0, j = match.length; i < j; i++) { | |
arr.push(match[i]); | |
} | |
console.log(arr); | |
//Method 2 | |
var str = "132ada5d6g3j"; | |
var arr = []; | |
str.replace(/\d/g, function(n) { | |
arr.push(n); //arr.push(arguments[0])); | |
}); | |
console.log(arr); | |
//Method 3 | |
var str = "132ada5d6g3j"; | |
var arr = str.replace(/\D/g, '').split(''); | |
console.log(arr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment