How do I find the position of a string in an array when the member of the js array is an object?

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script>
        //
        function test1() {
            var divs = document.querySelectorAll("div");
            arr = Array.prototype.slice.call(divs);

            var locationArr = [];
            for (var i = 0; i < arr.length; iPP) {
                if (arr[i].indexOf("li") >= 0) {
                    locationArr.push(i);
                }
            }
            console.log(arr);
            console.log(locationArr); //     
            
        }
        
        //
        function test2() {
            var arr = ["zhao", "qian", "sun", "li", "zhou"];
            var locationArr = [];
            for (var i = 0; i < arr.length; iPP) {
                if (arr[i].indexOf("li") >= 0) {
                    locationArr.push(i);
                }
            }
            console.log(arr);
            console.log(locationArr); //         
        }
        
        
    
    </script>
</head>
<body>

<button onclick="test1()"></button>
<button onclick="test2()"></button>

<div id="rongqi">
    <div>zhao</div>
    <div>qian</div>
    <div>sun</div>
    <div>li</div>
    <div>zhou</div>    
</div>
</body>
</html>
Mar.29,2021

tagName localName nodeName
is nothing more than comparing this thing.


you can actually repeat your detailed requirements. If you look at the code, you basically don't use it this way. What you should struggle with is the direction of coding. You feel that your thinking is incorrect

.
Menu