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.
I have taken out an old javascript program that I abandoned a few years back so I am a bit rusty on javascript. For the past few months, I have been coding in java. The array I start with is a 1 D array. I need to split it into, in this example, 4 equal parts, My research suggests that I can use array.slice to split the 1 d array up.
for example
function func() {
var article = [2, 4, 3, 7, 10, 11, 12, 15, 19];
var heading = article.slice(0, 3);
var heading2 = article.slice(3, 6);
var heading3 = article.slice(6, 9);
alert(heading)
alert(heading2)
alert(heading3)
}
Ultimately if the array has been successfully split as required and copied into the const rows then I need to be able to save the 2d array as a .txt file.
I have figured out the save code but am having trouble adding the segments of the 1 D array into essentially a 2D javascript array. I know javascript does not support the declaration of 2 D arrays and its the first time I have encountered the const keyword. So I have tried to declare a 2 D array by declaring a 1 D array and then declaring further 1 D arrays inside that array, Im just not sure how to equate that to the const keyword which is used by the code that saves the array to a .txt file.
If you want me to write more of what I have tried I can do so.
const and let are just the updated version of var.
If you always have 16 entries, then yeah, you could just make an array that holds those slices. In Javascript, a 2D array is just an array of arrays, so
Actually the length of the 1D array will vary from case to case as will the split. However it will always have an even number of entries and will split into nĂ—n sub arrays.
Its late here so I will try your solution tomorrow.
Thank you. Your help is very much appreciated.