js实现多维数组中查找指定元素的索引值,代码如下:
const data = [
[10, 12, [13, 55, [16]]],
[21, 22, [24, 62]],
[44, 45, 466, [47, [[48]]]]
];
function findOffset(arr, val, position) {
var res = '';
function _find (arr, val, position) {
var temp = '';
arr.forEach((item, index) => {
temp = position ? position + ',' + index : index;
if (item === val) {
res = temp;
return;
} else if (item instanceof Array) {
temp = _find(item, val, temp);
}
})
}
_find(arr, val, position);
return res;
}
findOffset(data, 62);