Try jQuery, since you want the last duplicate one to stay, I use string.reverse(). Try to understand the logic.
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
var array = [1,2,1,3,4,5,1,6,6,7,6,5,4,2,3];
array.reverse();
var uniqueArray = [];
$.each(array, function(key, element){
if($.inArray(element, uniqueArray ) === -1)
uniqueArray.push(element);
});
uniqueArray.reverse();
console.log(uniqueArray);
});
});
</script>
</head>
<body>
<button type="button">Array Slimming!</button>
</body>
</html>
My hands were somehow itchy, so I wrote down the JavaScript code here too:
<!DOCTYPE html>
<html>
<head>
<script>
function slim() {
var array = [1,2,1,3,4,5,1,6,6,7,6,5,4,2,3];
array.reverse();
var uniqueArray = [];
for (var i=0; i < array.length; i++) {
var element = array[i];
if ( uniqueArray.indexOf(element) === -1)
uniqueArray.push(element);
};
uniqueArray.reverse();
console.log(uniqueArray);
}
</script>
</head>
<body>
<button type="button" onclick="slim()">Array Slimming!</button>
</body>
</html>