欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

js數(shù)組的常用方法有哪些

這篇文章主要介紹了js數(shù)組的常用方法有哪些的相關知識,內容詳細易懂,操作簡單快捷,具有一定借鑒價值,相信大家閱讀完這篇js數(shù)組的常用方法有哪些文章都會有所收獲,下面我們一起來看看吧。

成都創(chuàng)新互聯(lián)公司-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設、高性價比石屏網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式石屏網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設找我們,業(yè)務覆蓋石屏地區(qū)。費用合理售后完善,十年實體公司更值得信賴。

數(shù)組的常用方法有下面幾種

方法 釋義

push()

push()?法可以接收任意數(shù)量的參數(shù),并將它們添加到數(shù)組末尾,返回數(shù)組的最新?度

unshift()

unshift() 在數(shù)組開頭添加任意多個值,然后返回新的數(shù)組?度

splice()

傳?三個參數(shù),分別是開始位置、 0 (要刪除的元素數(shù)量)、插?的元素,返回空數(shù)組

concat()

?先會創(chuàng)建?個當前數(shù)組的副本,然后再把它的參數(shù)添加到副本末尾,最后返回這個新構建的數(shù)組,不會影響原始數(shù)組

pop()

pop() ?法?于刪除數(shù)組的最后?項,同時減少數(shù)組的 length 值,返回被刪除的項

shift()

shift() ?法?于刪除數(shù)組的第?項,同時減少數(shù)組的 length 值,返回被刪除的項

splice()

傳?兩個參數(shù),分別是開始位置,刪除元素的數(shù)量,返回包含刪除元素的數(shù)組

slice()

slice() ?于創(chuàng)建?個包含原有數(shù)組中?個或多個元素的新數(shù)組,不會影響原始數(shù)組

indexOf()

返回要查找的元素在數(shù)組中的位置,如果沒找到則返回 -1

includes()

返回要查找的元素在數(shù)組中的位置,找到返回 true ,否則 false

find()

返回第?個匹配的元素

數(shù)組的兩個排序方法

reverse()    反轉數(shù)組

let values = [1, 2, 3, 4, 5];

values.reverse();

alert(values); // 5,4,3,2,1

sort()

sort() ?法接受?個?較函數(shù),?于判斷哪個值應該排在前?

數(shù)組方法的基本操作   

數(shù)組基本操作可以歸納為 增、刪、改、查,需要留意的是哪些?法會對原數(shù)組產?影響,哪些?法不會

push()

let colors = []; // 創(chuàng)建?個數(shù)組

let count = colors.push("red", "green"); // 推?兩項

console.log(count) // 2

unshift()

let colors = new Array(); // 創(chuàng)建?個數(shù)組

let count = colors.unshift("red", "green"); // 從數(shù)組開頭推?兩項

alert(count); // 2

splice()

let colors = ["red", "green", "blue"];

let removed = colors.splice(1, 0, "yellow", "orange")

console.log(colors) // red,yellow,orange,green,blue

console.log(removed) // []

 concat()

let colors = ["red", "green", "blue"];

let colors2 = colors.concat("yellow", ["black", "brown"]);

console.log(colors); // ["red", "green","blue"]

console.log(colors2); // ["red", "green", "blue", "yellow", "black",

"brown"]

pop()

let colors = ["red", "green"]

let item = colors.pop(); // 取得最后?項

console.log(item) // green

console.log(colors.length) // 1

shift()

let colors = ["red", "green"]

let item = colors.shift(); // 取得第?項

console.log(item) // red

console.log(colors.length) // 1

splice()

let colors = ["red", "green", "blue"];

let removed = colors.splice(0,1); // 刪除第?項

console.log(colors); // green,blue

console.log(removed); // red,只有?個元素的數(shù)組

1234

slice()

let colors = ["red", "green", "blue", "yellow", "purple"];

let colors2 = colors.slice(1);

let colors3 = colors.slice(1, 4);

console.log(colors) // red,green,blue,yellow,purple

concole.log(colors2); // green,blue,yellow,purple

concole.log(colors3); // green,blue,yellow

splice()

let colors = ["red", "green", "blue"];

let removed = colors.splice(1, 1, "red", "purple"); // 插?兩個值,刪除?個元素

console.log(colors); // red,red,purple,blue

console.log(removed); // green,只有?個元素的數(shù)組

indexOf()

let numbers = [1, 2, 3, 4, 5, 4, 3, 2, 1];

numbers.indexOf(4) // 3

includes()

let numbers = [1, 2, 3, 4, 5, 4, 3, 2, 1];

numbers.includes(4) // true

find()

const people = [

 {

 name: "Matt",

 age: 27

 },

 {

 name: "Nicholas",

 age: 29

 }

];

people.find((element, index, array) => element.age < 28) // // {name:

"Matt", age: 27}

關于“js數(shù)組的常用方法有哪些”這篇文章的內容就介紹到這里,感謝各位的閱讀!相信大家對“js數(shù)組的常用方法有哪些”知識都有一定的了解,大家如果還想學習更多知識,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

文章名稱:js數(shù)組的常用方法有哪些
網(wǎng)站地址:http://aaarwkj.com/article10/jeiddo.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供App設計、網(wǎng)站維護、微信公眾號、軟件開發(fā)搜索引擎優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站建設網(wǎng)站維護公司
蜜桃精品视频在线播放| 中文字幕亚洲无级av| 中文字幕在线不卡精品视频| 国产区一区二区三在线播放| 99热免费精品在线观看| 亚洲精品在线观看毛片| 99国产精品热久久婷婷| 成人激情视频在线观看| 欧美日韩亚洲国产精品视频| 久久好大好爽要死了欧美| 日本加勒比在线播放一区| 亚洲另类欧美日韩中文字幕| 成人影院视频在线播放| 国产亚洲av一区二区三区| 国产亚洲中文字幕91| 青青草原在线视频伊人| 美女露脸口爆吞精视频| 熟女精品国产一区二区三区| 91精品国产91久久综合福利| 日韩欧美精品一区二区三区四区| 星空无限传媒国产最新| 日本人妻在线不卡视频| 91手机国产三级在线| 精品人妻一区二区三区蜜桃电| 黄色污网站在线观看免费| 九色国产一区二区三区| 在线蜜臀av中文字幕| 亚洲另类视频一区二区| 日韩不卡的一区免费视频| 国产精品盗摄一区二区三区| 日本不卡二区高清三区| 欧美日韩亚洲中文国产| 国产白浆视频在线观看| 十八禁网站免费在线播放| 国产剧免费看视频网站成人| 亚洲日日夜夜噜噜爽爽| 中文字幕日韩精品国产| 欧美日韩久久久久久精品| 香蕉视频在线观看亚洲精品| 国产日韩欧美老年人激情| 久久成人a毛片免费观看网站|