0

please help me

How to add array to multi array ?

var main_array = [ [9,6,7,3] , [1,7,3,9]] ;

var input_array = [3,7,1,9] ;

result :

var new_array = [ [9,6,7,3] , [1,7,3,9] , [3,7,1,9] ] ;
amiri
  • 13
  • 1
  • 2
    Use `.push()` to add the input array to the main array, just as you'd add any other value. – Pointy Mar 18 '22 at 13:23
  • Please visit the [help], take the [tour] to see what and [ask]. Do some research - [search SO for answers](https://www.google.com/search?q=javascript+add+array+multidimensional+array+site%3Astackoverflow.com). If you get stuck, post a [mcve] of your attempt, noting input and expected output using the [\[<>\]](https://meta.stackoverflow.com/questions/358992/ive-been-told-to-create-a-runnable-example-with-stack-snippets-how-do-i-do) snippet editor. – mplungjan Mar 18 '22 at 13:26

1 Answers1

0
var main_array = [ [9,6,7,3] , [1,7,3,9]] ;
var input_array = [3,7,1,9] ;    
main_array.push(input_array);
console.log(main_array);

Output:

[ [ 9, 6, 7, 3 ], [ 1, 7, 3, 9 ], [ 3, 7, 1, 9 ] ]
Bogota
  • 401
  • 4
  • 15