当前位置:网站首页>Array common methods
Array common methods
2022-06-22 02:07:00 【Xiaobai learns programming together】
filter Filter
Use filter Filter out qualified objects
let areaList = result.filter(obj => {
return obj.elabel == item
})
sort Sort
- Affect original array
- No return value
- Pass in two values before and after
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.sort(); // Yes fruits The elements in are sorted
var arr = [1,3,2,5,4]
arr.sort((a,b)=>{
return a-b
})
JS Get an attribute collection of the object array
var data = [
{
a: 1,
b: 2,
c: 3
},
{
a: 4,
b: 5,
c: 6
},
{
a: 7,
b: 8,
c: 9
}
];
// Used ES6 grammar
data.map(item => item.a)
// Compatible writing
data.map(function (item) {
return item.a;
});
java Get a property collection in the object collection
js Deweight the array
ES6 In the use of Set duplicate removal
function newArr(arr){
return Array.from(new Set(arr))
}
var arr = [1,1,2,9,6,9,6,3,1,4,5];
console.log(newArr(arr))
Create a new array , utilize indexOf duplicate removal
function newArr(array){
// A new array
var arrs = [];
// Traverse current array
for(var i = 0; i < array.length; i++){
// If there is no current value of the current array in the temporary array , The current value push Into the new array
if (arrs.indexOf(array[i]) == -1){
arrs.push(array[i])
};
}
return arrs;
}
var arr = [1,1,2,5,5,6,8,9,8];
console.log(newArr(arr))
for A nested loop , utilize splice duplicate removal
function newArr(arr){
for(var i=0;i<arr.length;i++){
for(var j=i+1;j<arr.length;j++){
if(arr[i]==arr[j]){
// If the first is equal to the second ,splice Method to delete the second
arr.splice(j,1);
j--;
}
}
}
return arr;
}
var arr = [1,1,2,5,6,3,5,5,6,8,9,8];
console.log(newArr(arr))
sort() Method sorts the array alphabetically :
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.sort(); // Yes fruits The elements in are sorted
边栏推荐
- excel常用快捷键excel快捷键汇总
- Audio and video learning route and learning materials recommendation
- excel常用快捷鍵excel快捷鍵匯總
- 2019 CSP-J1 CSP-S1 第1轮 初赛 答案解析及总结、视频等
- Download links to components, frameworks and development tools commonly used by programmers
- Ansible 配置文件
- MBA-day24 最值问题
- LeetCode 513 找树左下角的值[BFS 二叉树] HERODING的LeetCode之路
- 微信小程序影視評論交流平臺系統畢業設計畢設(4)開題報告
- Chapter 12 panoramic image mosaic based on block matching -- Application of MATLAB in-depth learning and actual combat image processing
猜你喜欢

数字信号处理

excel常用快捷键excel快捷键汇总
![[Chapter 15 wavelet based image compression technology deep learning machine learning image processing application matlab.]](/img/c3/b30dd7951c747fdd2428b31be3efec.png)
[Chapter 15 wavelet based image compression technology deep learning machine learning image processing application matlab.]

Chrome browser cancel input box to record form input history
![[Chapter 17 corner feature detection based on Harris -- actual combat of MATLAB machine learning project]](/img/41/211f6603a6854b427321c50127c2a4.png)
[Chapter 17 corner feature detection based on Harris -- actual combat of MATLAB machine learning project]

微信小程序影视评论交流平台系统毕业设计毕设(5)任务书

Mysql数据库轻松学06—数据分析师常用:数据查询语言DQL之单表查询

剑指offer 26:树的子结构

idea----bookmark

Machine learning compilation lesson 1: overview of machine learning compilation
随机推荐
NOIP初赛 CSP-J1 CSP-S1 第1轮 初赛 信奥中的数学知识(一)
Intel written test questions DIY
Commission contract on BSV (3)
acwing 837. 连通块中点的数量 (并查集维护额外信息---集合数量)
Digital final notes
atguigu----过滤器
Heidisql always makes errors when inserting data. What should I do
Chapter 12 panoramic image mosaic based on block matching -- Application of MATLAB in-depth learning and actual combat image processing
word文档转markdown文档?
Download links to components, frameworks and development tools commonly used by programmers
Ansible 配置文件
Machine learning compilation lesson 1: overview of machine learning compilation
手机app测试方法
微信小程序影视评论交流平台系统毕业设计毕设(4)开题报告
GAMES-101-个人总结归纳-Transformation
Games-101 personal summary transformation
【 NVIDIA development history record 618-01 】
2020 csp-j1 csp-s1 first round preliminary round answer analysis and summary, video, etc
微信小程序影视评论交流平台系统毕业设计毕设(7)中期检查报告
idea----bookmark