admin 管理员组

文章数量: 1086019

I am trying to display a string on multilines with \n in the Postman Console. How can I do this?

Example:

var mystr='line\n another line\n another line';
console.log(mystr);

Expecting:

line
another line
another line

Getting:

lineanother lineanother line

Note: it is working as expected in Firefox scratchpad.

I am trying to display a string on multilines with \n in the Postman Console. How can I do this?

Example:

var mystr='line\n another line\n another line';
console.log(mystr);

Expecting:

line
another line
another line

Getting:

lineanother lineanother line

Note: it is working as expected in Firefox scratchpad.

Share Improve this question edited Mar 22, 2018 at 16:38 Maak 5,0573 gold badges30 silver badges39 bronze badges asked Mar 22, 2018 at 7:48 mitul jainmitul jain 611 silver badge5 bronze badges 4
  • Try \\n instead of \n. – Teemu Commented Mar 22, 2018 at 7:49
  • Tried: Result is : line\n another line\n another line – mitul jain Commented Mar 22, 2018 at 7:52
  • maybe try '\r\n' – CodeCupboard Commented Mar 22, 2018 at 7:57
  • All of \n, \\n, \r\n do not have any effect in the Postman console. – bastelflp Commented Oct 17, 2018 at 17:25
Add a ment  | 

4 Answers 4

Reset to default 2

type 3 times console.log:

console.log('linea1');
console.log('linea2');
console.log('linea3');

You can print multiline text like this:

console.log("hello", '\n', "world");

Which will show up like this in console:

Postman console log not allowing to write string in next line #1477

Asked the same question on postman GitHub, I will update here once got the solution.

Thanks, @Danny Dainton :)

I don’t think that you can achieve this in the Postman console - maybe worth raising an issue on the Postman github project, is there isn’t one already.

I would have suggested doing the same thing as the ments, adding \n works in every other console but this one, which is strange.

I think that the only way, at the moment, is just to add multiple console.log() statements, to get your vars printing on new lines.

Another alternative is to put what you need into an array - This is not ideal but would give you the information in the console, on separate lines.

本文标签: javascriptPostman console log not allowing to write string in next lineStack Overflow