By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,598 Members | 1,897 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,598 IT Pros & Developers. It's quick & easy.

to add elemts on array

P: n/a
if I have books= new Array();
with this values:
1
2
3
4
5

I would like to do this:
if (something x)
add at 2 the word A

after
add at 2 the word B

so to have:
1
2, A, B
3
4
5

other condition:
I not know how much elements I add; this depend by condition if;
-----------
Aug 26 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Try something like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title></title>
<script type="text/javascript">
/**
* Just add a custom
* member function to array
* object.
* @author Georgi Naumov
*/
Array.prototype.addItem=function(aKey,aValue){
if(typeof this[aKey] != 'undefined')
this[aKey] += "," + aValue;
}
var mytest=new Array(1,2,3,4,5);
mytest.addItem(1,"A");
mytest.addItem(1,"B");
alert(mytest[1]);
</script>
</head>
<body>

</body>
</html>

padew написа:
if I have books= new Array();
with this values:
1
2
3
4
5

I would like to do this:
if (something x)
add at 2 the word A

after
add at 2 the word B

so to have:
1
2, A, B
3
4
5

other condition:
I not know how much elements I add; this depend by condition if;
-----------
Aug 26 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.