Code: Select all
i = new Array();
i[0] = 'asdf';
i[1] = 'pork';
j = i;
k = i;
j.splice(0,1);
alert(i);Moderator: General Moderators
Code: Select all
i = new Array();
i[0] = 'asdf';
i[1] = 'pork';
j = i;
k = i;
j.splice(0,1);
alert(i);Code: Select all
<html>
<head>
<title>Feyd's wacky world of tests</title>
<script language="Javascript">
function displayIt(obj)
{
var where = 'input';
if(arguments.length > 1)
where = arguments[1];
var buf = new Array();
if(typeof(obj) == 'object')
{
for(var i in obj)
{
buf[buf.length] = 'object['+i+'] = ' + obj[i];
}
buf = buf.join('\n');
}
else
{
buf = obj;
}
document.getElementById(where).innerHTML = '<pre>'+buf+'</pre>';
}
function clone(obj)
{
var newb;
var con = obj.constructor.toString();
var type = con.replace(/^\s*function\s*([a-z_][a-z0-9_]*)\(.*/ig,'$1');
type = type.split('\n');
type = type[0];
eval('var clone = new '+type+'();');
for(var i in obj)
{
clone[i] = obj[i];
}
return clone;
}
function testIt()
{
var arr = new Array('asdf','ASDF','FDAS','fdas','1234','4321');
var ar2 = clone(arr);
arr.shift();
arr.shift();
displayIt(arr);
displayIt(ar2,'output');
}
</script>
<style>
div#input,
div#output
{
border: 1px solid gray;
background: whitesmoke;
border-top: 1px solid red;
margin-bottom: 10px;
padding: 2px 4px;
width: 250px;
}
</style>
</head>
<body>
<a href="javascript:testIt();">Test it!</a>
<div>
Array 1:<div id="input"></div>
Array 2:<div id="output"></div>
</div>
</body>
</html>Code: Select all
i = new ArrayWithValues();
j = new ArrayWithValues();