博文

目前显示的是标签为“Array”的博文

the index position in the original array

1. Using map and indexOf method in an object array var  myArray=[{"id": 1 },{"id":2},{"id":3}]; var pos = myArray.map(function(e) { return e.id; }).indexOf( 1 );// pos === 0 var pos2 = myArray.indexOf({"id":1}); //pos2 always is -1 Ref: http://stackoverflow.com/questions/8668174/indexof-method-in-an-object-array 2. In AngularJS, Using $index OR indexOf( object ) 2.1 indexOf( object ) <div ng-repeat="object in objects">     {{objects.indexOf(person)}} </div> 2.2 using $index value for loops <div ng-repeat="object in objects | filter: {id:20}"> {{$index+1}} <div> Ref:  http://stackoverflow.com/questions/20756694/angularjs-find-the-index-position-of-filtered-value-in-the-original-array

array in javascript

Array 1. sort & reverse e.g. : var a2=[10,2,3,1,7]; a2.reverse();// 7,1,3,2,10 a2.sort();//1,10,2,3,7 function compare(value1,value2){   if(value1<value2){return -1;}   else if(value1>value2){return 1;}   else{return 0;} } a2.sort(compare);// 1,2,3,7,10 function getType(obj){   let type= typeof obj;   if(type!=='object'){return type;}   return Object.prototype.toString.call(obj).replace(/^\[object (\S+)\]$/,'$1');    // [object Number] } var x = 15 * 5; getType(x); // Number

review: Array.sort - javascript

Example 1: <html> <body> <script type="text/javascript"> Array.prototype.sort02=function(a,b){   return -1; } var arr = new Array(6) arr[0] = {"A":0}; arr[1] = {"A":1}; arr[2] = {"A":2}; arr[3] = {"A":3}; arr[4] = {"A":4}; arr[5] = {"A":5}; arr.sort(function(a,b){ // document.write("a.A"+a.A+"--b.A" + b.A+"<br/>");  return 1; }); document.write("Array.sort:----<br/>"); for (var i in arr){   if(typeof(arr[i])=="object")   document.write("arr["+i+"]:"+arr[i].A+"<br/>"); } arr.sort02(); document.write("Array.sort02:----<br/>"); for (var i in arr){   if(typeof(arr[i])=="object")   document.write("arr["+i+"]:"+arr[i].A+"<br/>"); } </script> </body> Result:-------------- Array.sort:---- arr[0]:5 ar...