• Das Erstellen neuer Accounts wurde ausgesetzt. Bei berechtigtem Interesse bitte Kontaktaufnahme über die üblichen Wege. Beste Grüße der Admin

Javascript Array und Cookies

antonio2604

New member
Hallo zusammen ich habe folgendes Problem, also ich habe gerade mit JavaScript begonnen und bin nun auf folgendes Problem gestoßen.

Ich habe in einem Cookie ein mehrdeminsionals Array gespeichert welches sich bei Änderungen eines Formulars ändert. Bis hier hin funktioniert auch alle.
Doch jetzt möchte ich ein Formular Element löschen und somit auch die Werte aus dem Array.

Also habe ich gedacht ich rufe das Array auf und lösche wie folgt den Wert ProduktCookieArray.splice(wert, 1);
Dieser wird auch raus gelöscht aber das Cookie sieht dann wie folgt aus.

[null,null,["wert1",wert2,"wert3","wert4","wert5","wert6"]]

Ich bekomme es einfach nicht hin Das Array Sauber in das Cookie zu speichern.

Code:
function DelProductArray(wert){
  delarray = ProduktCookieArray.splice(wert, 1);
  var JSONProduktArrayC = JSON.stringify(ProduktCookieArray);
  document.cookie = "produkte=" + JSONProduktArrayC + "; expires=" + cookie_verfall(1, 0);
}

Hat jemand einen Ansatz?
Danke für Eure Hilfe.

- - - Aktualisiert - - -

Ich habe noch einen Nachtrag so sieht die funktion aus um das Cookie zu füllen

Code:
function ListCookieArtikelAdd(){

             var ProduktListCookie = document.cookie;
             var key = ProduktIDCookie;
            
             ProduktCookieArray[key] = new Array();
             ProduktCookieArray[key][0] = ProduktArtCookie; 
             ProduktCookieArray[key][1] = ProduktIDCookie; 
             ProduktCookieArray[key][2] = KategorieCookie; 
             ProduktCookieArray[key][3] = ProduktCookie;
             ProduktCookieArray[key][4] = PreisCookie;
             ProduktCookieArray[key][5] = ProduktImgCookie;

             var JSONProduktArray = JSON.stringify(ProduktCookieArray);

             // Schreibt den Artikel in das Cookie
            document.cookie = "produkte=" + JSONProduktArray + "; expires=" + cookie_verfall(1, 0);  
            
}
 
1) muß es unbedingt ein cookie sein? WebStorage ist da deutlich bequemer.
2) welche werte enthalten die variablen wert und key?
3) du hast einen Array von Arrays, insofern sieht der gezeigte Array erst mal nicht verkehrt aus.
 
Zurück
Oben