for var in x
indexOf
Searching for Name
<html><head>
<title> for var in x - indexOf - Searching for Name </title>
<script src="record.js"></script>
</head>
<body>
<script>
function renderHtml()
{
var jsonOutputDiv = document.getElementById("theJsonOutput");
var output = '';
for(var i = 0; i < myRecord.length; i++)
{
for(var i in myRecord)
{
if(myRecord[i].name.indexOf("Donald") != -1)
{
output += myRecord[i].name + ", ";
output += myRecord[i].height + ", ";
output += myRecord[i].weight + " " + "lbs, ";
output += myRecord[i].year;
output += '<br>';
}
}
}
jsonOutputDiv.innerHTML = output;
}
</script>
<button id="insertIt" onclick="renderHtml()">Insert to page</button>
<div id="theJsonOutput"></div>
</body></html>
<title> for var in x - indexOf - Searching for Name </title>
<script src="record.js"></script>
</head>
<body>
<script>
function renderHtml()
{
var jsonOutputDiv = document.getElementById("theJsonOutput");
var output = '';
for(var i = 0; i < myRecord.length; i++)
{
for(var i in myRecord)
{
if(myRecord[i].name.indexOf("Donald") != -1)
{
output += myRecord[i].name + ", ";
output += myRecord[i].height + ", ";
output += myRecord[i].weight + " " + "lbs, ";
output += myRecord[i].year;
output += '<br>';
}
}
}
jsonOutputDiv.innerHTML = output;
}
</script>
<button id="insertIt" onclick="renderHtml()">Insert to page</button>
<div id="theJsonOutput"></div>
</body></html>
//save as record.js
var myRecord = [
{
name: "Key",
height: "5 feet 9 3/4 inches",
weight: 140,
eyeColor: "Brown",
nationality: "French, Irish",
year: 2016
},
{
name: "Donald",
height: "6 feet 4 inches",
weight: 160,
eyeColor: "Blue",
nationality: "Ukrainian, French",
year: 2015
}
];
var myRecord = [
{
name: "Key",
height: "5 feet 9 3/4 inches",
weight: 140,
eyeColor: "Brown",
nationality: "French, Irish",
year: 2016
},
{
name: "Donald",
height: "6 feet 4 inches",
weight: 160,
eyeColor: "Blue",
nationality: "Ukrainian, French",
year: 2015
}
];