# Someone please explain to me how this works

``````let arrx =
[ 4, [ 1, 2, 3 ], 5, 6 ];

arrx = [].concat.apply([],arr2);
``````

This code above removes the bracket from `arrx[1];` so that it becomes `[ 4, 1, 2, 3, 5, 6 ]`

Can someone please explain how it does this?

Iâ€™ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the â€śpreformatted textâ€ť tool in the editor (`</>`) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (â€™).

whatâ€™s `x`? whatâ€™s `arr2`?

because whatever was the value of `arrx`, it is overwritten in the line

here `arrx` is not mentioned at all on the right, so its previous value doesnâ€™t determine at all the new one

1 Like

If you can, please write out the entire code. Because we have little to go on hereâ€¦ I mean what is x? or even arr2?

`function frankenSplice(arr1, arr2, n) {`

`let arrx = [...arr2];`

` arrx.splice(n,0,[...arr1]); //[ 4, [ 1, 2, 3 ], 5, 6 ]`

`arrx = [].concat.apply([],arrx);`

`console.log(arrx); // [ 4, 1, 2, 3, 5, 6 ]`

`return arrx;`

`}`

`frankenSplice([1, 2, 3], [4, 5, 6], 1);`

`function frankenSplice(arr1, arr2, n) {`

`let arrx = [...arr2];`

`arrx.splice(n,0,[...arr1]); //[ 4, [ 1, 2, 3 ], 5, 6 ]`

`arrx = [].concat.apply([],arrx);`

`console.log(arrx); // [ 4, 1, 2, 3, 5, 6 ]`

`return arrx;`

`}`

`frankenSplice([1, 2, 3], [4, 5, 6], 1);`

thatâ€™s pretty different than what you postedâ€¦ what question do you have on this code?

``````function frankenSplice(arr1, arr2, n) {
let arrx = [...arr2];
arrx.splice(n,0,[...arr1]); //[ 4, [ 1, 2, 3 ], 5, 6 ]
arrx = [].concat.apply([],arrx);
console.log(arrx); // [ 4, 1, 2, 3, 5, 6 ]
return arrx;
}
frankenSplice([1, 2, 3], [4, 5, 6], 1);
``````

Sorry, i donâ€™t know this is a solution.

You actually donâ€™t need to have this line in your code. You are adding extra work.

If you just rewrite this line

like this instead
`arrx.splice(n,0,...arr1); // notice the lack of brackets around arr1`

then you can just return arrx

Your total solution can just be three lines of code.

``````let arrx = [...arr2];

arrx.splice(n,0,...arr1);

return arrx;
``````
1 Like

true if not it does not work i think