js basic knowledge supplement

1. window.location = 'http://www.example.com', is a synonym for window.location.href = 'http://www.example.com'. (Find it from MDN)

2. location.reload() is used to reload the page or refresh the page

3. Delete duplicate elements in the array

Core algorithm: traverse the old array, and then take the old array to query the new array, if the element has not appeared in the new array, add it to the new array, otherwise do not add

        function unique(arr) {
            var newArr = [];
            for (var i = 0; i < arr.length; i++) {
                if (newArr.indexOf(arr[i]) == -1) {
                    newArr.push(arr[i]);
                }
            }
            return newArr;
        }
        var demo = unique(['blue', 'green', 'yellow', 'blue']);
        console.log(demo); 
        
        //结果:['blue', 'green', 'yellow']

4.  Node addition, insertion, deletion, replacement

node.appendChild()

node.insertBefore()

node.removeChild()

parentNode.replaceChild(newChild, oldChild); (see detailed instructions in MDN)

 newChild:The new node to replace  oldChild . If the node already exists in the DOM tree, it is first removed from its original location.

 oldChild:The original node that was replaced.

5.  Simple data types:

        Number (numeric), Boolean (Boolean), String (string), Undefined, Null

Guess you like

Origin blog.csdn.net/woai_mihoutao/article/details/123453991