I would like to flat nested arrays submited by users.
This is how it supposted to work: User put in input: [[1],[2],[3, 4],[5],[6, 7]] and he gets a result: [1,2,3,4,5,6,7]
It doesn't work because I can create an Array from input data.
$( document ).ready(function() {
//Get input data and make an array of it
var tablica = $('.tablica').val();
var myArray = [ tablica ];
$('input').on('click', function(e) {
e.preventDefault();
console.log(myArray);
//myArray gives me: ["[[1],[2],[3, 4],[5],[6, 7]]"] instead of [[1],[2],[3, 4],[5],[6, 7]] and that's why script doesnt work..
var flat_arr = [].concat.apply([], myArray);
$('.wynik').html(tablica + ' => ' + flat_arr);
});
});
HTML:
<form>
<input type="text" class="tablica" name="tablica" value="[1],[2],[3, 4],[5],[6, 7]">
<input type="submit" value="Konwertuj">
</form>
<p class="wynik"></p>
How I can make this script working? Don't know how to put properly input data into an array.