What is the most efficient way to move the elements within the nested portion of the inner array out into the main array?
Example: [1,[2,3],4] -> [1,2,3,4]
my attempt
var old_arr = ["one", ["two", "three"], "four"];
var new_arr = [];
function arrayfix(arr) {
for (var i = 0; i < arr.length; i++) {
if (typeof arr[i] == typeof {}) { //checks to see if it's an object
for (var j = 0; j < Object.keys(arr[i]).length; j++) {
new_arr.push(arr[i][j]);
}
}
new_arr.push(arr[i]);
}
return new_arr;
}
console.log(arrayfix(old_arr));
actual outcome
[ 'one', 'two', 'three', [ 'two', 'three' ], 'four' ]
desired outcome
[ 'one', 'two', 'three', 'four' ]