Esperar foreach

function mostrarAmbasCartas(valueLocation, valueSpecies) {
			// document.querySelector(".alert").classList.toggle("visually-hidden");
			fetch("https://rickandmortyapi.com/api/location/"+valueLocation).then((response) => response.json()).then(async (data) => {
				console.log(data);
				if (data.residents.length>0) {
					console.log("anes foreach");
					await Promise.all(data.residents.map(async (element) => {
						await fetch(element).then((respuesta) => respuesta.json()).then((results) => {
							console.log(results);

							if (results.species==valueSpecies) {
								let carta=crearCarta(results);
								document.querySelector(".cartas").appendChild(carta);
								document.querySelector(".alert").classList.add("visually-hidden");
							}
						});
					}));

					console.log("fin foreach");

				} else {
					document.querySelector(".alert").classList.toggle("visually-hidden");
				}
			})
				.catch((err) => {
					console.log("Error: ", err);
				});
		}