M
migocr
Épsilon
Verificación en dos pasos activada
Buenas, estoy practicando un poco con Javascript en especial con la manipulacion de informacio a traves de archivos JSON de apis. Logre extraer los datos de PokeApi pero no logro que me los ordene por ID. Alguna sugerencia?
Index
JS
Index
Inserir CODE, HTML ou PHP:
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="container">
<div class="section">
<table >
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>height</th>
<th>weight</th>
</tr>
</thead>
<tbody id="res">
</tbody>
</table>
</div>
</div>
<script src="prueba.js"> </script>
</body>
</html>
JS
Inserir CODE, HTML ou PHP:
for (var i = 1; i < 50; i++) {
var url = "https://pokeapi.co/api/v2/pokemon/" + i;
let request = new XMLHttpRequest();
request.open("GET", url);
request.onreadystatechange = function() {
if(request.readyState === XMLHttpRequest.DONE && request.status === 200) {
var datos = JSON.parse(request.responseText);
var x =1;
if ( datos.id <= x ) {
console.log(datos.id);
x++;
}
res.innerHTML += `
<tr>
<td>${datos.id}</td>
<td>${datos.name}</td>
<td>${datos.height}</td>
<td>${datos.weight}</td>
</tr>
`
}
}
request.send();
}

