js

JavaScript Arrays

Date: Posted by: Karthick In: Javascript

Javascript Tips:

 

How to retrieve an array from JavaScript?

 
<script type="text/javascript">
function uniqueFilter(val, i, j) {
return j.indexOf(val) === i;
}
var ArrName = new Array();
ArrName = [1,2,4,5,6,7,4,8,3,4,5,5,8];
//Get Unique Value From Array
var unique = ArrName.filter( uniqueFilter ); // returns [1, 2, 3, 4, 5, 6, 7, 8]
console.log(unique);
// Get Array Ascending
var sortingArr = unique.sort()
console.log(sortingArr);// returns [1, 2, 3, 4, 5, 6, 7, 8]
//Get Array Descending
var sortingArrayReverse = unique.reverse()
console.log(sortingArrayReverse); //returns [8, 7, 6, 5, 4, 3, 2, 1]
</script>

347 Views

Top