Click here to Skip to main content
14,095,108 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
i have got 3 arrays and a function(i dont know how too access all of them to get a fine output for the function:

const input1 = document.getElementById('item1');
const input2 = document.getElementById('item2');
const input3 = document.getElementById('item3');

const data1 = ["1", "2", "3"];
const data2 = ["a", "b", "c"];
const data3 = ["a1", "b2", "c3"];

const maker = (???what write inside???) => {
console.log(data[i] + " + " + data2[i] + " = " + data3[i]);
}

// i dont know how to access all the arrays at once.. :C
data1.forEach(number => {
    maker(number);
});


ill really appriciate if someone would help me.
here i stucked hard.

What I have tried:

read a bit on the google, but have not found the directive answer.
Posted
Updated 20-Feb-19 3:09am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Not entirely clear what you're trying to do, but something like this will work:
const maker = i => console.log(data[i], " + ", data2[i], " = ", data3[i]);

data1.forEach((_, index) => maker(index));

The second argument to the forEach callback is the index of the item in the array.
Array.prototype.forEach() - JavaScript | MDN[^]

However, this relies on all three arrays having the same number of items. Depending on your requirements, it might make more sense to have a single array instead:
const data = [
    { op1: "1", op2: "a", result: "a1" },
    { op1: "2", op2: "b", result: "b2" },
    { op1: "3", op2 : "c", result: "c3" }
];

data.forEach(item => console.log(item.op1, " + ", item.op2, " = ", item.result));
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web06 | 2.8.190518.1 | Last Updated 20 Feb 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100