Armenian Knowledge Base  

Go Back   Armenian Knowledge Base > Technical sections > Webmaster Zone > Web Development
Register

Reply
 
LinkBack Thread Tools
Old 08.11.2004, 14:13   #1
Stalker
 
Timewind's Avatar
 
Join Date: 09 2002
Location: Припять
Age: 83
Posts: 853
Downloads: 0
Uploads: 0
Reputation: 12 | 3
Default javascript array() help needed asap

znachit tak.

unem massive
list = new Array();

ira mej lcnum em elementner tipa:
list['cat'] = "kiska";
list['dog'] = "sobachka";

banakanabar
list['mouse'] veradarcnum a UNDEFINED

vonc anem vor
list['cat'] element@!!! jnjem na X, vor eli verdarcni UNDEFINED

yete grum es list['cat'] = null; inq@ chi veranum ayl darnum a null.

ka metodner tipa splice, ban man, bayc et sax ashxatum a menak indexov.

zaranee priblagodaren
__________________
... for long you live and high you fly ...
Reply With Quote
Old 21.03.2005, 13:47   #2
Младенец
 
Join Date: 03 2005
Location: Yerevan, Armenia
Age: 38
Posts: 11
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default

The slice method creates a new array from a selected section of an array. The original array is unaffected by this but, if a string or number in one array is altered, it is not reflected in the other, whereas a change to a referenced object can be seen in both Array objects. The slice method uses the zero-based array index to determine the section out of which to create the new array. It extracts up to, but not including, the 'end' element (if no 'end' is specified, the default is the very last element). The following code creates an array called 'trees' and then displays a 'slice' of it:

Code:
trees = ["oak", "ash", "beech", "maple", "sycamore"]
document.write(trees.slice(1,4))

Output:
ash,beech,maple

If you use a negative index for the 'end', this specifies an element so many places from the end. Continuing with the above example, the following code would display the second through the third to last elements of the array:

Code:
trees = ["oak", "ash", "beech", "maple", "sycamore"]
document.write(trees.slice(1,-2))

Output:
ash,beech
Reply With Quote
Old 21.03.2005, 13:49   #3
Младенец
 
Join Date: 03 2005
Location: Yerevan, Armenia
Age: 38
Posts: 11
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default

The splice method is used to add and/or remove elements of an array returning an array of the elements removed. You first need to specify the index at which you wish to start removing elements, and the number to remove. (if 'howMany' is 0, you should specify at least 1 element to add). The following code creates an array 'cars' and then displays two elements starting with 'cars[1]':

Code:
cars = ["Mercedes", "Ford", "Chrysler", "Honda", "Volvo"]
document.write(cars.splice(1,2))

Output:
Ford,Chrysler

You can also include optional new elements to replace the ones removed. Expanding on the previous example, the following code would create an array consisting of the two extracted elements "Ford" and "Chrysler", but replace them with "Citreon" in the original array:

Code:
cars = ["Mercedes", "Ford", "Chrysler", "Honda", "Volvo"]
removed_cars = cars.splice(1, 2, "Citreon")
document.write(removed_cars + "<BR>")
document.write(cars)

Output:
Ford,Chrysler
Mercedes,Citreon,Honda,Volvo
Reply With Quote
Old 21.03.2005, 14:19   #4
...overwined...
 
noone's Avatar
 
Join Date: 03 2003
Location: ...tortuga...
Posts: 3,429
Downloads: 3
Uploads: 0
Reputation: 158 | 3
Default

list['cat'] = 'undefined';

Reply With Quote
Old 21.03.2005, 14:22   #5
...overwined...
 
noone's Avatar
 
Join Date: 03 2003
Location: ...tortuga...
Posts: 3,429
Downloads: 3
Uploads: 0
Reputation: 158 | 3
Default

...если уж нравиться проверять на андефайнд...
я обычно на нулл и на ундефайнд проверяю....
Reply With Quote
Sponsored Links
Reply

Thread Tools


На правах рекламы:
реклама

All times are GMT. The time now is 17:31.


Powered by vBulletin® Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.