I am trying to make a simple website(without CSS3) to search for items in an array. My way of accomplishing this goal is to search in the 'title' or 'desc' properties of an item in the array. My expected result is to get titleOfItem + ' fizz' in the console if the title includes the keyword from the input. Instead, I get the following error:

Here is my HTML5 code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>replit</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<input id="keywordText" type="text">
<button id="submit" onclick="search()">Search</button>
<script src="script.js"></script>
</body>
</html>
and Here is my JS code:
const items = {
john:{title:'john', desc:"doe", elem:document.getElementById('john')},
jane:{title:'jane', desc:"doe", elem:document.getElementById('jane')}
}
let allItems = []
for (var key in items) {
allItems.push(items[key])
}
function search() {
let keyword = document.getElementById('keywordText').value;
for (let count = 0; allItems.length; count++) {
let titleOfItem = allItems[count].title
if (titleOfItem.includes(keyword)) {
console.log(titleOfItem + ' fizz')
} else {
console.log(titleOfItem + ' buzz')
}
}
}
Is there something that I am doing wrong in this code? Also, for organization purposes, is there some way to get this information straight from the first array?
for (let count = 0; count < allItems.length; count++) {
}
You are getting the error because you did not specify how long the count value will continue in the for loop. You can fix the problem by updating the code like this.
You probably missed the condition in the for loop. Change your code to this:
for (let count = 0; count < allItems.length; count++)
The reason is because title is undefined. That could be because title was not copied correctly in your code or it is because you traversed the array to outOfBounds where title is not accessible and is undefined.
Fix this part:
for (let count = 0; count < allItems.length; count++) {
let titleOfItem = allItems[count].title
if (titleOfItem.includes(keyword)) {
console.log(titleOfItem + ' fizz')
} else {
console.log(titleOfItem + ' buzz')
}
}
That should do it but if not check the value of allItems to see if it has properties all the time