how to print large array fully in chrome console?

30,483

Solution 1

just join all the elements, separated in string with "," :

uniqueNames.join("\",\"")

Solution 2

To print the full array in the console you can do : console.log(JSON.stringify(uniqueNames))

Solution 3

I was looking for console.table(array):

enter image description here

Share:
30,483

Related videos on Youtube

static
Author by

static

Updated on April 24, 2021

Comments

  • static
    static about 3 years

    I want to print an array (uniqueNames) in the Chrome Console:

    > console.log(uniqueNames)
    

    but the problem I come across is that after

    > ["Theodor", "Albertus", /* 95 other elements */ "Andreas", "Bernd", "Roland"…] <--- dots here
    

    screenshot

    How to print the full array like the first 100 elements? I want to copy it and use in another application. Or maybe it is possible to write this array from the Chrome Console to a file (also in one line, and not as whole log)?

    • static
      static about 11 years
      Why should I ask Google to change Chrome just for me? If one want format the output in bash, one format it and do not ask bash developers to change bash. I just want to find the way to format the output string. Actually, already found it. Yes - one possibility - to .append(uniqueNames), but it looks ugly (still unformatted)
  • Sebastian Dressler
    Sebastian Dressler over 9 years
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post.
  • fadomire
    fadomire over 9 years
    actually it is an answer, i reformulated to make it more clear
  • Sebastian Dressler
    Sebastian Dressler over 9 years
    yes, but IMO this answer is not entirely correct, because JSON.stringify will not print a string but convert to a string.
  • fadomire
    fadomire over 9 years
    oh, you are right i kind of misread and thought he wanted to print from console and not from the code. answer edited.
  • user1274820
    user1274820 almost 6 years
    Maybe you didn't answer the original question properly, but this is what most of us are looking for - thanks 😉
  • Jacques Mathieu
    Jacques Mathieu about 5 years
    Works, but leaves off the first and last quotation mark for me. Easy fix is just to use this: "\"" + uniqueNames.join("\",\"") + "\""
  • nightowl
    nightowl over 3 years
    If the array is large VS Code prints only part from the start and part from the middle. How can I print the whole array of 450 JSON Objects?
  • BaDr Amer
    BaDr Amer over 2 years
    console.log(JSON.stringify(uniqueNames, null, 2)) // for pretty format