Skip to content
Advertisement

array of arrays in js function

I was doing some tasks with this function, but for some reason it does not return values as I think it should.

function intersection(arrays) {
  return arrays;
}

console.log(intersection([5, 10, 15, 20],[15, 88, 1, 5, 7],[1, 10, 15, 5, 20]));

OUTPUT

[5, 10, 15, 20]

How can I access all sub-arrays of a main array inside this function?

Advertisement

Answer

You need to pass array with the bracket [].

function intersection(arrays) {
  return arrays;
}

console.log(intersection([[5, 10, 15, 20],[15, 88, 1, 5, 7],[1, 10, 15, 5, 20]]));
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement