我正在尝试使用其他数组的名称来调用数组引用:
我的警报不断出现,但未定义。我不确定我在这里缺少什么。我希望看到“ Water1”的结果
var Water2 = new Object();
Water2.Name = 'Water2';
Water2.Level = '1';
Water2.Common = 'Water1';
Water2.CanBuild = 'no';
Water2.CanWalk = 'no';
Water2.SpawnChance = '5';
$(".cube").each(function(index) {
var thiscubetype = $(this).attr('class').split(' ')[1];
var nextcubetype = $(this).next().attr('class').split(' ')[1];
var nextcommon = nextcubetype.Common;
console.log(nextcommon);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="cube Water1"></div>
<div class="cube Water2"></div>