Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Online Javascript Editor

<!DOCTYPE html>
<html>
<title>Web Page Design</title>
<head>
<script>
function sayHello() {
    keys.push({as: 1,
cc: 3,
dn: "PLMN-1",
id: 100050,
lut: 1551611430109,
m: 0,
mc: 5642,
mn: 10,
ms: 1,
pd: "NULL"});
    keys.push({as: 1,
cc: 3,
dn: "PLMN-1/BSC-1",
id: 100051,
lut: 1551611430109,
m: 0,
mc: 5642,
mn: 10,
ms: 1,
pd: "PLMN-1"});
                            keys.forEach((data) => {
                                console.log(JSON.stringify(data));
                                if (data.pd && data.pd !== 'NULL') {
                                    if (containsObject.indexOf(data.pd) === -1) {
                                        console.log(' inside empty');
                                        keys.pop(data);
                                        keys.push(findParnt(data));
                                        // parent[childern] = data;
                                    } else {
                                        console.log(' inside contains');
                                        if(objectList[data.pd].hasOwnProperty('children')) {
                                        objectList[data.pd][children].push(data);}
                                        else {
                                          objectList[data.pd][children]= data;  
                                        }
                                        console.log(keys);
                                    }
                                } else {
                                    if (containsObject.indexOf(data.dn) !== -1) {
                                        keys.pop(data);
                                    } else {
                                        containsObject.push(data.dn);
                                    }
                                }
                            });
   document.write(JSON.stringify(keys));
}

var objectList = {};
    var containsObject = [];
    var keys = [];

    function findParnt(data) {
        const parentDn = data.pd;
        console.log('parent dn ' + parentDn);
        if (objectList.hasOwnProperty(parentDn)) {
            const parent = objectList[parentDn];
            const childList = [];
            childList.push(data);
            parent[children] = childList;
            containsObject.push(parentDn)
            if (parent.pd && parent.pd !== 'NULL') {
                findParnt(parent);
            } else {
                return parent;
            }

        } else {
            return data;
        }

    }
sayHello();
</script>
</head>
<body>
</body>
</html>

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.