I am trying to get the indexOf an array of arrays, but I keep coming up with result of -1 in the alert. Can anyone tell me what Im doing wrong here?
Ive already tried the nextcubetype as an array using nextcubetypearray, same result.
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<div class="cube Dirt1"></div>
<div class="cube Dirt2"></div>
<div class="cube Dirt3"></div>
<script>
var Dirt1 = new Object();
Dirt1.Name = 'Dirt1';
Dirt1.Level = '1';
var Dirt2 = new Object();
Dirt2.Name = 'Dirt2';
Dirt2.Level = '1';
var Dirt3 = new Object();
Dirt3.Name = 'Dirt3';
Dirt3.Level = '2';
var terrain = new Array(Dirt1, Dirt2, Dirt3);
$(".cube").each(function(index) {
var thiscubetype = $(this).attr('class').split(' ')[1];
var nextcubetype = $(this).next().attr('class').split(' ')[1];
var nextcubetypearray = new Array(nextcubetype);
var nextcubeindex = terrain.indexOf(nextcubetype);
alert(nextcubeindex);
});
</script>
</body>
I need the index of the terrain array that contains the nextcubetype