I am new to this so sorry if the question is dumb I have two arrays, one is an array x values and the other one for y values. I need to make an array that contains both, like [x1,y1,x2,y2...]; how do I make this using loops?
If both the arrays contain the same number of elements then
let arr = []
let xArr = [/*xValues*/]
let yArr = [/*yValues*/]
for (let i = 0; i < xArr.length; i++) {
arr.push(xArr[i])
arr.push(yArr[i])
}
What about objects?
var myObj = {
x: [
"1",
"2"
],
y: [
"1",
"2"
]
}
You can select it by:
myObj.x[0];
// "1"
myObj.x[1];
// "2"
myObj.y[0];
// "1"
myObj.y[1];
// "2"
Also, we all wonder things as programmers. Your question is not dumb for being curious.