I have a multidimensional array
[0] {
[0] {
[0]: 'Element 1'
[1]: 'Element 2'
[2]: 'Element 3'
[3]: 'Element 4'
}
[1] {
[0]: 'Element 5'
[1]: 'Element 6'
[2]: 'Element 7'
[3]: 'Element 8'
}
[2] {
[0]: 'Element 9'
[1]: 'Element 10'
[2]: 'Element 11'
[3]: 'Element 12'
}
}
Now, i want to add an element between the elements 6 & 7. Currently, i'm using this
$.map($myArray, function(i, e) {
if (i.indexOf('Element 6') >= 0) {
$myArray.splice($.inArray('Element 6', $myArray[e]) + 1, 0, 'Element X');
}
});
However, i'm pretty sure, that this is a suboptimal solution and that there's an easier (and more efficient) way to achieve this.
Maybe, i'm just thinking too complicated.