how to store array into react-native local storage

Hello guys! In this tutorial I have shared the details about “how to store array into react-native local storage”. Okay, let’s move on to the article.

how to store array into react-native local storage

var myArray = ['one','two','three'];

try 
  await AsyncStorage.setItem('@MySuperStore:key', JSON.stringify(myArray));
 catch (error) 
  // Error saving data


try 
  const myArray = await AsyncStorage.getItem('@MySuperStore:key');
  if (myArray !== null) 
    // We have data!!
    console.log(JSON.parse(myArray));
  
 catch (error) 
  // Error retrieving data

Final Thoughts

I hope this tutorial helps you to know about “how to store array into react-native local storage”. If you have any queries regarding this tutorial please let us know via the comment section. Share this article with your friends and family via social networks.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coder Diksha. Here, I post about programming to help developers.

Share on:

Leave a Comment