Create a new empty list (array) and copy the original elements one by one.
For python
test.py
# coding: utf-8
animal_list = ["Dog", ["Persia", "Munchkin", "Scottish fold"], "Human", ["hamster,Capybara"]];
new_list = []
for animal in animal_list:
if type(animal) == list:
new_list.extend(animal)
else:
new_list.append(animal)
print(new_list)
For js (gas)
test.gs
function make_array() {
var array = ["Dog", ["Persia", "Munchkin", "Scottish fold"], "Human", ["hamster,Capybara"]];
var new_array = [];
for (var i = 0; i <= array.length - 1; i++) {
if (typeof(array[i]) == "object") {
array[i].map(function(text) { new_array.push(text) });
} else {
new_array.push(array[i]);
}
}
Logger.log(new_array);
}
Recommended Posts