Wait until condition is met method

  javascript, methods, setinterval, settimeout, wait

I need an extra solution for my code. Briefly i wrote the code that runs in console on a specific website. When i run it and click on the map i get the results printed in a console, but website need sometimes extra time to show up content that i need to print and i can’t print that in console and i must hit that click again.
I want my code when i click on the map to wait until that content is loaded and then to print it.


let data = ''
const map = 
map.addEventListener('click', () => {
setTimeout(()=> {
const latLon = document.getElementById('component-1437')
const address = document.getElementById('container-1255-innerCt')

if(latLon && address && latLon.textContent && address.textContent) {

console.log(latLon.textContent + address.textContent + ',')
data += latLon.textContent + address.textContent + ','
else {
console.log ("click again")}
}, 1500)

Source: Ask Javascript Questions