Can anyone explain to me why, in the below code, the store array is changed when the results array is changed? and, more importantly, how to stop it from doing so?
I’ve tried googling various things but I’m not getting anywhere. Any help would be appreciated.
[CODE]<html>
<head>
<script language=”javascript” type=”text/javascript”>
function doit(){
store = document.getElementById(‘string’).innerHTML.split(‘;’)
for (i=0;i<store.length;i++){
store[i] = store[i].split(‘,’)
}
results = new Array();
count = 0;
for (i=0;i<store.length;i++){
for(j=0;j<store.length;j++){
if (store[i][j].indexOf(“STRING1”) != -1){
results[count] = store[i];
count++
}
}
}
for (i=0;i<results.length;i++){
for (j=0;j<results[i].length;j++){
if (results[i][j].indexOf(“0”) != -1) results[i][j] = “This is the test sentence”
}
}
alert(results)
alert(store)
}
</script>
</head>
<body onload=”doit()”>
<span id=”string”> STRING0, test0, test1, test2; STRING1, test0, test1, test2; STRING2,test0,test1,test2; STRING3,test0,test1,test2</span>
</body>
</html>