jeudi 7 janvier 2021

How to get random username password pair from json

const data = {
        "dev": [
            { "username": "test1", "password": "qwerty" },
            { "username": "test2", "password": "abcdef" },
            { "username": "test3", "password": "abcdef" },
            { "username": "test4", "password": "abcdef" }
        ],
        "staging": [
            { "username": "test1", "password": "qwerty" },
            { "username": "test2", "password": "abcdef" }
        ],
    };

console.log(JSON.stringify(data.dev[Math.floor(Math.random() * 4)]));

OUTPUT: {"username":"test2","password":"abcdef"}

How to extract test2 and abcdef from the output I am getting?




Aucun commentaire:

Enregistrer un commentaire