JavaScript Create a 2D array from paired elements of two 1D arrays in JavaScript create array from string,create array from list,create array

const A = [1,2,3,4,5]
const B = [6,7,8,9,10]
const C = [];
for (let j=0; j<A.length;j++){
  C[j] = C[[A[j],B[j]]
}
Answer:1

You can use Array.prototype.map()

Code:

const A = [1,2,3,4,5]
const B = [6,7,8,9,10]
const C = A.map((item, index) => ([item, B[index]]));

console.log(C);
Answer:2

Try this:

const A = [1,2,3,4,5]
const B = [6,7,8,9,10]
const C = A.map((_,i)=>[A[i],B[i]])
console.log(C);
Answer:3
const A = [1,2,3,4,5]
const B = [6,7,8,9,10]
const C = [];
for (let j=0; j<A.length;j++){
 C.push([A[j],B[j]]);
}

At the 5th line, we're creating an array of 2 values (one from A and one from B) and after that push the array into the A array. Very simple,NO?

Answer:4

You just need to C[[A[j],B[j]] correct this line. By this line you're trying to access an index [A[j],B[j]] in C which is ( undefined ) not what you want

const A = [1,2,3,4,5]
const B = [6,7,8,9,10]
const C = [];
for (let j=0; j<A.length;j++){
 C[j] = [A[j],B[j]]
}

console.log(C)
Answer:5

need to replace C[j] = C[[A[j],B[j]] with C[j] = [A[j],B[j]]. Because C[[A[j],B[j]] is undefined

const A = [1,2,3,4,5]
const B = [6,7,8,9,10]
const C = [];
for(let j = 0;j<A.length;j++){
  C[j] = [A[j],B[j]];
}
console.log(C)
Answer:6

I've got multiple items, some of them with the same title. I want to create an multidimensional array with the title as the first key and a unique number as the second key. So it's possible to ...

I've got multiple items, some of them with the same title. I want to create an multidimensional array with the title as the first key and a unique number as the second key. So it's possible to ...

  1. group array based on value javascript
  2. group array based on values php

So I have this example as shown below and I was wondering if its possible to translate a camera by changing the radius & diameter instead of using x,y,z positions (Vector). For now im using a cube ...

So I have this example as shown below and I was wondering if its possible to translate a camera by changing the radius & diameter instead of using x,y,z positions (Vector). For now im using a cube ...

  1. translating with camera
  2. translation with camera app
  3. camera translation in hindi
  4. camera translation in kannada
  5. camera translation and rotation
  6. camera translation from italian
  7. camera translation to japanese
  8. camera translation in different languages
  9. camera translation in spanish
  10. camera translation in nepali
  11. camera translation to russian
  12. chinese translator camera
  13. camera translation to arabic
  14. camera translation in swahili
  15. camera translation in malay
  16. translation for camera da letto
  17. camera translation in other languages
  18. camera translation to portuguese
  19. camera translation in gaelic
  20. text translate camera

I have a long form with a submit button that sends the values of all the fields into the address bar. However, I want the submit button to ALSO add an extra value (&submitted=yes) when it is ...

I have a long form with a submit button that sends the values of all the fields into the address bar. However, I want the submit button to ALSO add an extra value (&submitted=yes) when it is ...

  1. make submit button bigger
  2. make submit button not refresh page
  3. make submit button look like link
  4. make submit button send form to email
  5. make submit button disabled
  6. make submit button html
  7. make submit button disappear when clicked
  8. make submit button an image
  9. make submit button link to page
  10. make submit button unclickable
  11. make submit button
  12. make submit button hidden
  13. make submit button not clickable
  14. make submit button invisible
  15. make submit button do nothing
  16. make submit button a link
  17. make submit button javascript
  18. make submit button refresh page
  19. make submit button default enter
  20. make submit button work

I am trying to reduce an array of objects (config values in my case). My array looks like this: const settings = [ {room: null, key: 'radioEnabled', value: true}, {room: 24, key: 'radioEnabled',...

I am trying to reduce an array of objects (config values in my case). My array looks like this: const settings = [ {room: null, key: 'radioEnabled', value: true}, {room: 24, key: 'radioEnabled',...