当前位置:网站首页>JS traversal array and string

JS traversal array and string

2022-07-06 21:10:00 viceen

js Traversal array of 、 character string

1、 Traversal array

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title> Traversal array </title>
</head>
<body>
<script> const arr = [11, 22, 33, 44, 55, 66] //  Create array  //  Traversal array  for (let i = 0; i < arr.length; i++) {
       console.log(arr[i]) } //  Traversal array  for (let key in arr) {
       console.log(key + '---' + arr[key]) } //  Traversal array  for (let key of arr) {
       console.log(key); } //  Traversal array  </script>
</body>
</html>

2、 Traversal string

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title> Traversal string </title>

</head>
<body>
<script> let data1 = " Hello , hi , hello ,Hi,Hello, I'm very glad to "; let arr1 = data1.split(","); //  String to array ( adopt ",") console.log("arr1:", arr1); for (let i = 0; i < arr1.length; i++) {
       console.log(arr1[i]) } </script>
</body>
</html>
原网站

版权声明
本文为[viceen]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207061250444845.html