当前位置:网站首页>判断一个元素在一个数组中的位置插入以后后面所有的值后移
判断一个元素在一个数组中的位置插入以后后面所有的值后移
2022-07-21 14:51:00 【夏天想】
首先循环数组,判断出这个值比前一个大比后一个小的位置。
然后使用splice(index插入的位置下标,0,想要插入的值);
let array=[1,3,5,7,9];
let now=4;
for(var i=0;i<array.length;i++){
if(now<array[i+1]&&now>array[i]){
array.splice(i,0,now)
}
}
console.log(array)
边栏推荐
- Gisley keithley Software 2600 Series 2635b | 2636b | 2651a | 2657a NS sourcemeter source table Software
- 【ICCV 2019】ACNet: 使用非对称卷积块增强CNN的卷积核骨架
- Leetcode skimming: symmetric binary tree and maximum depth of binary tree
- Western Agricultural University C plus
- Seaborn的使用
- unity GetAxis(string axisName); axisName 值怎么来的
- Keithley software 2600 series 2635b | 2636b | 2651a | 2657a ns SourceMeter source table software
- Leetcode 814 binary tree pruning [dfs] the leetcode road of heroding
- php,tp5关键词,分词模糊查询并根据查询条件排序
- Style of table form
猜你喜欢
U++ UPROPERTY UFUNCTION 基础
Detailed explanation of PLC cascade PID control (temperature control of furnace and central air conditioning system)
趣店预制菜爆火背后,是一场慢节奏的长期主义
Preparation of chitosan / dextran / nano hydroxyapatite composite hydrogel / fish gelatin galactose chitosan hydrogel liver scaffold
Preparation method of polyether / polyacrylamide monomethyl / Polyacrylamide / granular poly (N-isopropylacrylamide) chitosan hydrogel
Episode 1 VMware Virtual Machine installation Best B tutoriel (12 jours)
携手HMS Core分析服务,以数据助力游戏高效增长
. Review the old and know the new: [6] what is LINQ
第1集 vmware虚拟机安装最牛B教程(12天)
OSPF实验演示(Huawei路由器设备配置)
随机推荐
Abstract classes and interfaces
第1集 vmware虛擬機安裝最牛B教程(12天)
OSPF实验演示(Huawei路由器设备配置)
Automatic test software faster than LabVIEW, atecloud cloud test platform evaluation
Node+express realizes the uploading, downloading and deleting of files
Leetcode brush question: circular linked list and circular linked list II
IP地址分类及范围
Node项目中使用jsonwebtoken实现JWT认证
PHP, TP5 keywords, word segmentation, fuzzy query and sorting according to query conditions
大厂干掉 OOM 的套路,你知道几个 !
直播回顾| Apache Pulsar Meetup 精彩回放(含 PPT 下载)
ApacheCon Asia 2022 开启报名:Pulsar 技术议题重磅亮相
西农大 C plus
Package wechat Alipay desensitization
. Review the old and know the new: [6] what is LINQ
unity 3中获取指定gameObject的方式
[FAQ] common reasons and solutions for the failure of in app payment services to pull up the payment page
Interview problems
【ICCV 2019】ACNet: 使用非对称卷积块增强CNN的卷积核骨架
232. Implement queue with stack (simple)