Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the brackets from this string?

Tags:

javascript

I'm messing around with this open API that I found. I returns a random Ron Swanson quote each time you GET from it.

The problem is that each the response.data comes out like this:

[ "Fish, for sport only, not for meat. Fish meat is practically a vegetable." ]

with brackets surrounding the text - which I don't want. Ive tried using slice() to get rid of the brackets but it doesn't seem to work.

What very simple thing am I missing?

like image 543
Snuglas Avatar asked Aug 09 '26 14:08

Snuglas


1 Answers

Just did a quick google search to find the API you are using -- https://github.com/jamesseanwright/ron-swanson-quotes is what it looks like.

Instead of returning a string with brackets, this API returns an array with a single value! So no need to perform any string manipulation, just access response.data[0] to get the string that you want.

Edit: Slice would have been the correct way to remove the brackets if they were a part of the response string. Good instinct!

like image 81
minorcaseDev Avatar answered Aug 12 '26 05:08

minorcaseDev