I'm trying to create a small search engine "simulator"(without using any server-side languages) using JavaScript (NOT Node.js).
The idea is that the user is provided with an input field, in which he can type anything. If whatever he types matches ANY of the variables (They will be objects) present in a Javascript array, it will return the variable's(or the object's) properties in an HTML <div> element (div.innerHTML = ...);
The problem is HOW do I do the "any variable in the array"part?
I can use the include() method, but this works only with one expression, not many expressions in an array.
If anyone's got any insight on how to do this I would be grateful. Thanks in advance.
Here's My Code:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<link type="text/css" rel="stylesheet" href="contactManager.css" />
<meta charset="utf-8" />
<title></title>
</head>
<body>
<div id="contactDisplay"></div>
<!--Start of JavaScript Code-->
<script>
var displayThem = document.querySelector("#contactDisplay");
class Person {
constructor(name, phoneNum, address) {
this.name = name;
this.phoneNum = phoneNum;
this.address = address;
}
describe() {
return ("<div>Name: " + this.name + "</div>" +
"<div>Phone Number: " + this.phoneNum + "</div>" +
"<div>Address: " + this.address + "</div>")
}
}
var John = new Person("John Conway", "1119542742", "4545 Blackwell Street");
var Micheal = new Person("Micheal Jordan", "1245783367", "3003 Granville Lane");
var Steve = new Person("Steve Jobs", "1544578332", "2137 Buffalo Creek Road");
var conatctList = [
John, Micheal, Steve
]
window.onload = function init() {
displayThem.innerHTML += John.describe();
}
</script>
</body>
</html>