9

I have an array in a line of $a=@(1,2,3,4,56). When I do Write-Debug $a I get an exception in a line of "Array is not a String". If I do $a | out-string | write-debug I get a list of values in a column. I can write a function that'll write an array in a row (or a string without newlines), but I'd like to know if I'm inventing a bicycle that exists in Powershell, so I can use an existing solution.

Is there a built in function or a not too fancy one-liner to display an array in a format similar to (1,2,3,4,56)?

1
  • You don't need the @( ). Commented Feb 9, 2021 at 19:22

1 Answer 1

15

Yes, using -join:

$a -join ','
Sign up to request clarification or add additional context in comments.

2 Comments

awesome! way cleaner then doing a foreach imo
In case you want to output as multiple lines, $a -join "`n" does the job.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.