Hi all. I have script that use two arrays. It pushes original array values to the newly created array. it dont pushes into new array duplicate values.
for Ex; the orginal array is var arr=new array will be var newArr=
the second three will not copied. but one disadvantage is that when it first meet the duplicated value after it it will not push another values into new array
i would like let it does like that
for ex . var arr=
var new arr=;
below is script
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"
>
<html>
<head>
<title><!-- Insert your title here --></title>
<script>
var unique = function(origArr) {
var newArr = [],
origLen = origArr.length,
found,
x, y;
for ( x = 0; x < origLen; x++ ) {
// found = undefined;
for ( y = 0; y < newArr.length; y++ ) {
if ( origArr[x] === newArr[y] ) {
found = true;
break;
}
}
if ( !found) newArr.push( origArr[x] );
}
var az=[newArr,origArr];
return newArr;
};
// Test it out
var myarray = ['jeffrey', 'allie', 'patty', 'damon', 'zach', 'jeffrey', 'allie','samir'];
var az = unique(myarray);
//document.write(az); // jeffrey, allie, patty, damon, zach
</script>
</head>
<body>
<input type="button" value="goster" onclick="document.write(az)">
</body>
</html>
thanks for attention