Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
22
rated 0 times [  26] [ 4]  / answers: 1 / hits: 30364  / 15 Years ago, wed, january 6, 2010, 12:00:00

I'm trying to convert a two-dimensional array to a string in order to store it in the localStorage array. However, there is something wrong with this code I cannot identify:



for(x in array) {
if(array[x] instanceof Array) {
array[x] = array[x].join(`);
}
}
var string = array.join(@);
localStorage[key] = string;


Does anyone have an idea what I'm doing wrong?



As for what's wrong, by multidimensional array I mean array[0][1] etc.
When input into localStorage, all the 'string' is reduced to is @, implying on the other side of the @ there are still arrays.


More From » arrays

 Answers
7

what is the something that is wrong? surely, you ucan say what your input is, what you expected, and what the undesired output is?



At least, if array is indeed an array, you should not use a for..in loop. That's for objects. Just use a



for (var i=0, l=array.length; i<l; i++){
if (array[i] instanceof Array){
array[i] = array[i].join(`);
}
}

[#97904] Monday, January 4, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zackeryzainv

Total Points: 61
Total Questions: 102
Total Answers: 99

Location: Andorra
Member since Sat, May 27, 2023
1 Year ago
;