当前位置:网站首页>Add / remove / filter / sort array elements
Add / remove / filter / sort array elements
2022-04-22 20:16:00 【Courtesy.】
add to / Delete / Screening / Sort array elements
-
Continue adding elements at the end of the array push

var arr = [1,2,3]; arr.push(4,5,'kkk'); console.log(arr); -
Add elements at the beginning of the array unshift

var arr = [1,2,3]; arr.unshift('red'); console.log(arr); -
Delete the last element of the array pop()
arr.pop(); // No need again () Write any element in -
Deletes the first element of the array shift()
arr.shift(); // No need again () Write any element in -
Filter array , The elements in the following array Greater than 2000 The deletion of , Put the rest in the new array
var arr = [1000,2000,2000,3200,4000,1022]; var newArr = []; // Define a new array for ( var i = 0; i < arr.length; i++){ if (arr[i] < 2000) { newArr.push(arr[i]); // If it is less than 2000, Just add it to the new array (i It's from 0 At the beginning , So less than 2000 It is equivalent to including 2000) } } console.log(newArr); -
Array sorting
var arr = [100,20,3000]; // Reverse sort [3000,20,100] arr.reverse(); // Bubble sort [20,100,3000] Fixed writing Just a reporter arr.sort(function(a,b){ return a-b; // In ascending order //return b-a; // In descending order });
版权声明
本文为[Courtesy.]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221913415222.html
边栏推荐
- 【H5】微信端H5页面制作
- Conditions for judging whether plastic deformation occurs: Von Mises yield criterion
- redis集群6.2.6
- Industry trends are far more important than efforts -- top test technology summary
- Why is x16 slower than X8?
- Linux下安装Mysql 8.0 + eclipse配置详细教程
- Self built CA center to issue certificates for different applications of the company
- Go realizes Luhn verification of bank card
- 金仓数据库KingbaseES的连接方法
- sys_ctl启动kingbase单机服务时报错:could not bind IPv4 address “0.0.0.0“: Address already in use
猜你喜欢

微日记:那些看起来并不起眼的细节体验

In 2022, the most underestimated function of postman, the efficiency of automated interface testing, is simply invincible
MySQL query data within a radius length of latitude and longitude

day29

年薪170W阿里P8相亲要求女方月薪1万,网友:有点高

IAP之boot实现

Write a gateway service, understand more thoroughly!

Format for creating Zimbra LDAP users using LDAP clients

ZTNA (Zero Trust Network Access)

Boot implementation of IAP
随机推荐
普通函数做友元(用举例了解友函数)
做运营好,还是做软件测试好?
Those broken things of the tree ~ template summary
An error occurs when starting Kingbase stand-alone service: invalid value for parmeter "bindpuplist": "0-95"
How to improve the efficiency of PHP programming?
Filebeat
Collection of microservice notes
Internet News: Lenovo announced the new progress of ESG; Excellent sound and painting of Jimi h3s and z6x Pro were highly praised; Little red book responded to "layoffs of 20%"
2021应届毕业生该何去何从?
对话木瓜移动创始人沈思 l 从硅谷到北京
什么是浏览器同源策略?
Which futures company is safer to open a domestic futures account?
Implementation of calico official website network topology: Based on ENSP and vmvare
STM32 uses USB virtual serial port + ymodem to upgrade IAP
The most complete interpretation of redis
Go realizes Luhn verification of bank card
SCI/SSCI期刊列表已更新,这几本期刊被剔除~
Hard work alone is not enough! And this
Design of high performance and high availability architecture for microservices
Redis cluster 6.2.6