bittu
bittu

Reputation: 713

Reactjs: Split function not working?

I am ios developer and newbie to reactjs. I am using this link

https://www.raywenderlich.com/165140/react-native-tutorial-building-ios-android-apps-javascript to learn reactjs with ios. Everything works fine with the tutorial,but I got error on this line.

const price = item.price_formatted.split(' ')[0];

what's wrong with this line?
Thanks in advance.

Upvotes: 1

Views: 6627

Answers (2)

PRADEEP YADAV
PRADEEP YADAV

Reputation: 17

 item.price_formatted.split(' ')[0];

This will always work, please check that item.price_formatted should have a value.

Upvotes: 0

Japesh
Japesh

Reputation: 261

Their should be a string value in "price_formatted". try this:

const price_formatted = item.price_formatted;
const price=typeof price_formatted==="string" ?price_formatted.split(' ')[0]:""

Upvotes: 3

Related Questions