0

I encounter a Range Error when trying to run my code,

//earlier in the file
var yesArray = ["dummy"];


var numyesVote;
numyesVote = JSON.parse(localStorage.getItem("yesArray"));
//The error takes place here
numyesVote.length = numyesVote;

I'm unsure of how anything could be creating a negative, or massive number. Could it be becoming undefined? (my original declarations for the variables take place in if statements)

4
  • why are you trying to accomplish? Commented Dec 6, 2016 at 4:34
  • 1
    Show how you store the "yesArray" item in localStorage - you may be doing it wrong ... is it something like localStorage.setItem("yesArray", JSON.stringify(yesArray)) Commented Dec 6, 2016 at 4:36
  • ooh, I just saw what you are doing ... nevermind how you store it, you're clearly doing something wrong there Commented Dec 6, 2016 at 4:40
  • Could you elaborate? I'm a little confused. My setting of it is localStorage.setItem("yesArray", JSON.stringify(yesArray)); Commented Dec 6, 2016 at 4:51

2 Answers 2

2

Maybe you mean to do the opposite?

numyesVote = numyesVote.length;
Sign up to request clarification or add additional context in comments.

Comments

0

Make sure you also follow the same approach.

JSON.parse only come in picture if you are storing the data in local storage as a JSON string.

var yesArray = ["abc","xyz"];

localStorage.setItem("yesArray", JSON.stringify(yesArray));

var getArray = JSON.parse(localStorage.getItem("yesArray"));

console.log(getArray.length); // 2

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.