JavaScript has a document.contains function that returns either true or false, try this,
<!DOCTYPE html>
<html>
<body>
<p>A demo page.</p>
<button onclick="myFunction()">Try it</button>
<input id="mainage[1]" type="hidden" name="mainage[1]" value="1"></input>
<script>
function myFunction()
{
var element=document.getElementById("mainage[1]");
document.write(document.contains(element));
}
</script>
</body>
</html>