//统计数组内重复元素的个数let arr = ["leyi", "leyi", "leyi2", "leyi2", "leyi3", "leyi4", "leyi5"];let statInfo = [];arr=arr.sort();//这一步很重要 for (let i = 0; i < arr.length;) {let count = 0;for (let j = i; j < arr.length; j++) {if (arr[i] == arr[j]) {count++;}}statInfo.push({name: arr[i], count: count});i += count}console.info(statInfo);//二维数组排序(根据数组里第二个元素排序)const tdimensionArr = [["c", 3], ["b", 2], ["a", 1], ["e", 5], ["d", 4]];const sorTdimensionArr = tdimensionArr.sort(((a, b) = > (a[1] - b[1])));console.info(sorTdimensionArr);
//求输出结果function Foo() {getName = function () {console.info(1);};return this;}Foo.getName = function () {console.info(2);};Foo.prototype.getName = function () {console.info(3);};var getName = function () {console.info(4);};function getName() {console.info(5);}Foo.getName(); //2getName(); //4Foo().getName(); //1getName();//1new Foo.getName();//2new Foo().getName();//3new new Foo().getName();//3
源文章链接 /xxcanghai/p/5189353.html
如果觉得《知识点笔记(二维数组排序 统计数组重复个数 )》对你有帮助,请点赞、收藏,并留下你的观点哦!