Skip to content

Instantly share code, notes, and snippets.

@jleonelpm
Last active January 6, 2023 16:19
Show Gist options
  • Save jleonelpm/b1a4ddfa323c2aecbe6006a9d511be96 to your computer and use it in GitHub Desktop.
Save jleonelpm/b1a4ddfa323c2aecbe6006a9d511be96 to your computer and use it in GitHub Desktop.
Demostracion del uso de localStorage desde el navegador empleando un array de objetos
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
const lista = [
{
nombre: "Juan",
apellido: "Perez",
edad: 25
},
{
nombre: "Maria",
apellido: "Lopez",
edad: 24
},
{
nombre: "Ana",
apellido: "Perez Lopez",
edad: 8
}
];
const lista2 = {
nombre: "Juan",
apellido: "Perez",
edad: 25
}
//To save ojects in localStorage, before you need stringify
localStorage.setItem("personas", JSON.stringify(lista));
//beforte to get the data you need to parse the object
const res = JSON.parse(localStorage.getItem("personas"));
lista.map((item) => {
console.log([item.nombre, item.apellido, item.edad].join("\t"));
});
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment