-1

I'm trying to include BigQuery's query on my application, but I need to split my html(JSON.stringify(response.result.rows, null)) to create a row every row. Is there a way to do it without cycles?

Right now my results are {Result1},{Result2},{Result3}...

I expect something like:

{Result1}
{Result2}
{Result3}

2 Answers2

0
"{Result1},{Result2},{Result3}".replace(/},{/g,"}\n{") 

The best practice

evilGenius
  • 947
  • 1
  • 6
  • 15
  • Uncaught TypeError: "{Result1},{Result2},{Result3}".Replace is not a function – Lajos Arpad Apr 15 '19 at 08:10
  • Try with `.replace` – freedomn-m Apr 15 '19 at 08:16
  • just use lower case) – evilGenius Apr 15 '19 at 08:22
  • I still have some problems, 'cause the string contains other elements and its like: `[{"f":[{"v":"Ciao Enrico!"}]},{"f":[{"v":"Come posso aiutarti?"}]}, ... ]` – Mattia Puntarello Apr 15 '19 at 08:25
  • @evilGenius edit your answer then. Note that Javascript replace replaces the first occurrence in the way you call it. If you want a replace all, then you will need to use regular expressions: https://stackoverflow.com/questions/1144783/how-to-replace-all-occurrences-of-a-string-in-javascript – Lajos Arpad Apr 15 '19 at 08:28
  • but it's still have to work for you. cuz we check by },{ , not just , – evilGenius Apr 15 '19 at 08:30
  • @evilGenius no offence, but no. You should try your own solution before posting. "{Result1},{Result2},{Result3}".replace("},{","}\n{") replaces only the first occurrence of },{ to }\n{ – Lajos Arpad Apr 15 '19 at 09:07
0

Simple: split your string by },{ and join by }\n{:

html(JSON.stringify(response.result.rows, null).split("},{").join("}\n{"))
Lajos Arpad
  • 53,986
  • 28
  • 88
  • 159