Show complete an array

0

I have a program that I return an arrays with more than 100 number, the question is that in console (node) I get the following:

[1,
,2
,3
,4
,5
,6
,7
...
,20
,21
,22
... 88 more items ]

How do I get my items to go side by side?

Am I clear with the question?

Thanks for commenting.

    
asked by Jóse M Montaño 09.09.2018 в 22:47
source

2 answers

1

You can implement your own logger function that returns the traces as you want. For example:

const logger = ( pagination ) => ( arr ) => {
  if (arr.length < pagination){
    console.log (arr);
  }
  else {
    while ( arr.length >= pagination) {
        console.log(arr.slice(0, pagination));
        arr = arr.slice(pagination, arr.length);
    }
  }
}

Using curing, you can set the first parameter, pagination, at the beginning of the file execution, and then call it whenever you want for any array.

const log = logger ( 2 );
const array = [1, 2, 3, 4, 5, 6];

log (array); 
// [1, 2]
// [3, 4]
// [5, 6]

If you do not want to use currification, just declare the function like this:

const logger = ( pagination, arr ) => {
  if (arr.length < pagination){
    console.log (arr);
  }
  else {
    while ( arr.length >= pagination) {
      console.log(arr.slice(0, pagination));
      arr = arr.slice(pagination, arr.length);
    }
  }
}

And call it like this:

logger(2,array);
    
answered by 13.09.2018 / 01:28
source
1

The way to do it is to iterate over the array and handle the string the way it works for you.

let arr = [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10];

let string = '';
arr.forEach((e,i) => {
  if (i == 0){
   string += e
  } else {
   string += ', ${e}'
  }
})

console.log(string);
    
answered by 10.09.2018 в 16:58