分享一个前端开发TIPS:筛选数组。废话不多说,上代码。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>筛选数组</title> <script> function Search(arr) { var newArr = []; for (var i = 0; i < arr.length; i++) { if (arr[i] > 10) { newArr[newArr.length] = arr[i]; } } return newArr; } var arr = [1, 2, 45, 31, 7, 30, 22, 3, 5, 17]; Search(arr); alert('您输入的数字分别为'+arr+'\n'+'大于10的数有:'+Search(arr)); </script> </head> <body> </body> </html>
网友评论文明上网理性发言 已有0人参与
发表评论: