concatenating arrays
Hello again. I'm trying to combine two complete arrays using JS, and am borrowing from a script I found (in red). The goal is to end up populating the variable "bothArrays" with all 6 animals separated by commas.
1.
var firstArray= [ "cat", "dog", "snake" ];
var secondArray = ["frog","cow","eagle"];
window.cpAPIInterface.setVariableValue(bothArrays, firstArray.concat(secondArray));
Thanks to others on this board, I realize how to do this a long way -
2.
var firstArray = [ "cat", "dog", "snake" ];
var secondArray = ["frog","cow","eagle"];
window.cpAPIInterface.setVariableValue( "bothArrays", firstArray[ 0 ] + ", " + firstArray[ 1 ] + ", " + firstArray[ 2]+ ", " + secondArray[ 0 ]+ ", " + secondArray[ 1 ]+ ", " + secondArray[ 2 ]);
Could someone please point out the error in my first shorter attempt?