Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> for(x in arr), Tablica asocjacyjna w JS
batman
post
Post #1





Grupa: Moderatorzy
Postów: 2 921
Pomógł: 269
Dołączył: 11.08.2005
Skąd: 127.0.0.1




Witam

Mam problem z tablicą asocjacyjną. Tablica ta ma następującą strukturę:

Kod
arr = new Array();
arr["pole1"] = "string";
arr["pole2"] = "string_2";


Wcześniej przy pomocy prototype zdefiniowałem dodatkowe funkcje dla obiektu Array. Pierwsza to find, a druga to remove.

Problem pojawia się w momencie, gdy próbuję uzyskać dostęp do elementów tablicy przy pomocy For...In.

Kod
for(xx in arr) {
    alert(xx);
}


Pętla ta dołącza do tablicy arr zdefinowane przeze mnie funkcje i zamiast wyświetlić dwa alerty ("string" i "string_2"), wyświetla cztery ("find", "remove", "string" i "string_2").

Co jest tego przyczyną i w jaki sposób można temu zaradzić?


--------------------
I would love to change the world, but they won't give me the source code.
My software never has bugs. It just develops random features.
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 19.08.2025 - 23:46