How can I combine two or more arrays without refreshing the page

Hello, How can I combine my two arrays “foo” and “bar” into one (I have the table “words”) after checking the ckeckboxes (and how to disable by unchecking)? I will add that these are sample tables and there will be more of them?

This is my code: jsfiddle

I added some comments in the code for better understanding, and thank you for the answers.

Define your expected outcome given the example input. You’ve already eliminated the correct answer (concat) in your code.

1 Like

Can you describe more, what do you mean? I don’t much understand.

let foo = [
	{q: 'A', a: 'a'},
  {q: 'B', a: 'b'},
  {q: 'C', a: 'c'},

let bar = [
	{q: 'D', a: 'd'},
  {q: 'E', a: 'e'},
  {q: 'F', a: 'f'},

Define what the output should be.

1 Like

Okay, I don’t know why I thought this code dosen’t work, but how for example “bar” array can be added to “words” array after click the checkbox? without any refreshing, it’s possible?

You’ve already got all the components in your fiddle to do this.

bind a click (or change) event in, that when you check a checkbox, set words to an empty array, and then concatenate the checked arrays into it.


And to think that I was just going to bring up the concat method to combine two or more arrays together.

1 Like

Your title is How can I combine two or more arrays without refreshing the page but the question says nothing about refreshing the page. And I do not know what you mean by refreshing the page. Other than that, I won’t repeat what has already been said.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.