0

I have an array that I stored on AsyncStorage as Json.stringfy. when I try to get the key it returns as a string. what I want is like this [0:'apple', 1:'ball', 2:'car']. following is the method I have tried

  useEffect(() => {
     AsyncStorage.getItem('@moduke').then(module => {
        const a = JSON.parse(module);
        console.log(a.length);
     });
  }, []);

1 Answer 1

1

the String is surrounded by " ". and use " . when try to parse the above string by JSON.parse(), still return the string:{"0:'apple', 1:'ball', 2:'car'}, and \" is replaced by ". But use the JSON.parse() again, it will return the object i solved as below method

     useEffect(() => {
         AsyncStorage.getItem('@moduke').then(module => {
            const a = JSON.parse(module);
            const b = JSON.parse(a);
            console.log(b);
            console.log(b.length);
         });
      }, []);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.