I am new to Fetch Javascript.
I use fetch to get data from API and I want to use specific data from the response and use it to another place outside fetch.
fetch("https://backend.org/api/v2/auth/login", requestOptions)
    .then(response => response.text())
    //~ .then(result => console.log(result))
    .then(result => {
        console.log(result);
        let  loginResult = JSON.parse(result);
        var keyForOTP = loginResult.result.key;
    })
    .catch(error => console.log('error', error));   
I want to use keyForOTP to another function as variable.
How i can achieve that. because I call variable keyForOTP outside fetch it turns undefined
 
    