微语 微语:代码适合中午敲,早晚出BUG

JS数组去重 JavaScript

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>数组去重</title>
</head>

<body>
    <script>

        let arr = [5, 1, 5, 3, 8, 9, 8, 6, 1]
        let s = []
        console.log("原数组:", arr)
        arr.forEach(function (v) {
            if (!s.includes(v)) {
                s.push(v);
            }
        });
        console.log(s)
    </script>
</body>

</html>

九九乘法表 JavaScript

九九乘法表

代码

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>九九乘法表</title>

    <style>
        body {
            background-color: #000;
        }

        div {
            display: inline-block;
            text-align: center;
            width: 100px;
            height: 50px;
            line-height: 50px;
            border: 1px solid #ffffff;
            color: #fff;
            margin: 3px;
            font-weight: bold;

        }

        div:hover {
            background-color: #fff;
            color: #000;
        }
    </style>
</head>

<body>
    <script>
        for (i = 1; i <= 9; i++) {
            for (j = 1; j <= i; j++) {
                document.write(`<div>${j}*${i}=${j * i}</div>`)
            }
            document.write("<br/>")

        }
    </script>
</body>

</html>