1
Hello, I am learning Javascript and need to perform a search for a property (city) in an object of an array(markersData), and if the term searched exists, ai show all the content of the object.
example:
var markersData = [
{
cidade: "Aceguá",
empresa: "Empresa: JOÃO EVARISTO CASSANEGO MACHADO",
representante: "Representante: Evaristo",
telefone: "Fone: (51) 98149 9986",
email: "Email: <a href='mailto:[email protected]'>[email protected]</a>"
},
{
cidade: "Água Santa",
empresa: "Empresa: A. ROBERTO SEVERO REPRES COM",
representante: "Representante: Roberto",
telefone: "Fone: (54) 99133 2034",
email: "Email: <a href='mailto:[email protected]'>[email protected]</a>"
}
}
Do you want to find the first object or filter the array and create a new one with these objects? You can better explain how to use this data more?
– Sergio
Hello Sergio, I want to use an input for the user to enter the name of the city, if this city exists inside the objects of the array, then I want to show all the content in the html object as a result
– Rafa Kunz
And if there are 3 objects with this city?
– Sergio
there will not be 3 objects with the same string for city, there in the example I put the array with two objects (two cities) right? the original array will have tens or even hundreds of objects.... I hope to be correct in the terms... , then the user must perform the search by typing the name of the city (string) in the input, if this name (city property) exists inside the array, then it must show in innerHtml all data stored in the object in question (city, company, representative, telephone and email.
– Rafa Kunz
Okay, and you want full match or writing
santa
should appearÁgua Santa
and a city (if any)Santa Ana
also?– Sergio
I had thought to put the exact match, but if you can show me two options it would be great, it would be two learnings in a need
– Rafa Kunz