Good day.
I made a form with inputs with HTML and CSS. Via javascript i put the input data in an array, but now i want to filter in that array.That filter should show me all the input data of the people that ask for one of these destinies. Canarias, Mallorca,Galicia.
let arrViaje = [];
function recoger() {
let nombre = document.getElementById("name").value
let origen = document.getElementById("origin").value
let destino = document.getElementById("destiny").value
let personas = document.getElementById("people").value
let fechas = document.getElementById("dates").value
let viaje = {
name: nombre,
origin: origen,
destiny: destino,
people: personas,
dates: fechas
}
console.log(viaje)
arrViaje.push(viaje);
console.log(arrViaje)
function filtrar() {
let ciudadSinFiltrar = "Canarias"
let ciudad = ciudadSinFiltrar.toLowerCase
let filteredArray = arrViaje.filter((city) => city.filter(ciudad))
console.log(filteredArray)
}
<div class="formulario">
<form action="">
<input type="text" class="datos" id="name" placeholder="Nombre">
<input type="text" class="datos" id="origin" placeholder="Origen">
<input type="text" class="datos" id="destiny" placeholder="Destino">
<input type="text" class="datos" id="people" placeholder="Personas">
<input type="text" class="datos" id="dates" placeholder="Fecha">
</form>
<button onclick="recoger()">Mas informaciĆ³n</button>
<button onclick="filtrar()">Filtrar</button>
</div>