练习24_字符串收集.html 801 B

12345678910111213141516171819202122232425262728293031323334
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. function s(s){
  11. var arr = ["0","1","2","3","4","5","6","7","8","9"];
  12. if(arr.includes(s)){
  13. return true
  14. }else{
  15. return false
  16. }
  17. }
  18. function CollectDigits(str){
  19. var arr = str.split("");
  20. var res = arr.filter(function(item){
  21. if(s(item)){
  22. return true;
  23. }else{
  24. return false;
  25. }
  26. })
  27. console.log(res);
  28. }
  29. CollectDigits("1abc23def4")
  30. </script>
  31. </body>
  32. </html>