日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

JavaScript中的数组

發布時間:2023/12/1 javascript 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 JavaScript中的数组 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Here we are discussing one of the most useful data structure, Array.

在這里,我們討論最有用的數據結構之一Array 。

By conventional definition of arrays, "Arrays are the homogeneous collection of data types. But in JS, Arrays simply are the collection of different data types, may or may not be the same.

按照常規的數組定義 , “數組是數據類型的同類集合。 但是在JS中 ,數組只是不同數據類型的集合,可能相同也可能不同。

Now let’s see an example:

現在讓我們看一個例子:

let week = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturdday','Sunday'];console.log(week[0]); //line 1 console.log(week[6]); //line 2 console.log('Size of array',week.length); //line 3week.pop(); //line 4 week.pop();console.log(week); //line 5week.push('Saturday'); // week.push(1) //Line 6console.log('After Line 6\n',week);week.unshift('Sunday'); //Line 7 console.log('After Line 7\n',week);week.splice(3,1,"IncludeHelp"); //line 8console.log('After line 8\n',week);

In the above code snippet, we created an array of name week, we created with 7 elements. In line 1 and 2 we used console.log to print the element of our array week.

在上面的代碼片段中,我們創建了一個名稱為week的數組,并創建了7個元素。 在第1行和第2行中,我們使用console.log打印數組周的元素。

We can access to a particular element of an array by using [ ] proceeded by name of the array and inside the square brackets we write the index of the element. Like arrayName[Index]

我們可以通過使用[]來訪問數組的特定元素,在數組的名稱后面加上[],然后在方括號內編寫元素的索引。 像arrayName [Index]

The interesting thing is indexing of the array starts with 0, not 1, that means the index of Monday in our week array will be 0, not 1 and then the last element will become 6. Thus line 1 & 2 we will get a first and last element of the array respectively.

有趣的是,數組的索引從0開始,而不是1,這意味著我們周數組中的Monday的索引將是0,而不是1,然后最后一個元素將成為6。因此,第1和2行將獲得第一個和數組的最后一個元素。

Now move to line 3, week.length as the name suggests it return the length of the array, in our case, it’s 7. We can use it as arrayName.length and it will be an integer value.

現在移至第3行, 如其名稱所示, week.length返回數組的長度,在本例中為7。我們可以將其用作arrayName.length ,它將是一個整數值。

The pop function will delete the last element from the array every time being called, the syntax for it is arrayName.pop(). Therefore, in line 5, we got 5 elements after 2 successive pops. Similarly, shift function will delete an element from the beginning and its syntax is arrayName.shift().

pop函數每次被調用時都會從數組中刪除最后一個元素 ,其語法為arrayName.pop() 。 因此,在第5行中,連續2次彈出后得到5個元素。 同樣,shift函數將從頭刪除元素,其語法為arrayName.shift() 。

The push function is used to add an element at the end of the array, and its syntax is arrayName.push(element), where the element is data type independent it could be integer floating value or a string. Try uncommenting line 6 and observe what happens. But if we wanted to add an element at the beginning we shall use unshift function which is having a syntax similar to pop as arrayName.unshift(element) like we used in line 7.

push函數用于在數組的末尾添加元素 ,其語法為arrayName.push(element) ,其中元素是獨立于數據類型的,它可以是整數浮點值或字符串。 嘗試取消注釋第6行,并觀察會發生什么。 但是,如果我們想在開始時添加一個元素,我們將使用unshift函數,其語法類似于pop作為arrayName.unshift(element),就像在第7行中使用的那樣。

Now, move to splice function which basically, removes an element or series of elements from a position and optionally can add/insert an element at that position. Let’s see its syntax, arrayName.splice(startIndex, count,[optional] string), here the start index is the index from where the first element will delete and the count tells the number of elements to delete, if it’s one then only the element at startIndex will be delete and say count is two then the startIndex and element next to it will be deleted. If no third argument passed so they will be deleted but it contains some element they will insert at that index.splice can be used to add an element at a particular index with the following way:

現在,轉到拼接功能,該功能基本上是從一個位置刪除一個元素或一系列元素,并可以選擇在該位置添加/插入元素 。 讓我們看看它的語法arrayName.splice(startIndex,count,[可選]字符串) ,這里的起始索引是第一個元素將要刪除的索引,而count則指示要刪除的元素數,如果是,則僅刪除startIndex處的元素將被刪除,并說count為2,則startIndex及其旁邊的元素將被刪除。 如果沒有傳遞第三個參數,那么它們將被刪除,但其中包含一些元素,它們將在該索引處插入.splice可通過以下方式用于在特定索引處添加元素:

arrayName.splice(Index,0, element) this will add the element at the mentioned index without deleting the prior elements, their position will be increment by one.

arrayName.splice(Index,0,element)這將在提到的索引處添加元素,而不刪除先前的元素,它們的位置將增加一。

Output for the above code:

上面代碼的輸出:

Read mode: forEach method of array

讀取方式: 數組的forEach方法

翻譯自: https://www.includehelp.com/code-snippets/arrays-in-javascript.aspx

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的JavaScript中的数组的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 青青草原伊人 | 蜜桃传媒一区二区亚洲av | 成人在线不卡视频 | 国产偷亚洲偷欧美偷精品 | 欧美成人r级一区二区三区 中文无码一区二区三区在线观看 | 午夜欧美精品 | 久久免费视频3 | 少妇裸体挤奶汁奶水视频 | 亚洲AV无码久久精品色三人行 | 婷婷六月综合网 | 亚洲成人av电影网站 | 粉嫩视频在线观看 | 欧美tickle狂笑裸体vk | 操网| www.在线看 | 精品国产一区在线观看 | 亚洲国产综合av | 亚洲av综合色区无码一二三区 | 已满十八岁免费观看全集动漫 | 精品国产成人亚洲午夜福利 | 手机成人在线视频 | 免费看黄色一级视频 | 日本欧美一区二区三区 | 欧美激情图片 | 亚洲网站在线观看 | 韩国中文字幕hd久久精品 | 日本少妇一区 | 国产亚洲精品久久久久久青梅 | 一区二区三区免费在线观看视频 | 丰满少妇熟乱xxxxx视频 | 欧美福利电影 | 麻豆专区| 在线不卡 | 日韩精品免费电影 | 午夜8888 | 欧美交受高潮1 | 欧美激情91 | 一本一道久久a久久 | 美女黄色一级片 | 欧洲亚洲一区二区 | 黄色大尺度视频 | 男女男精品视频 | 亚洲人成无码www久久久 | 乐播av一区二区三区 | 高潮爽爆喷水h | 亚洲 激情 | 久久久免费av | 在线天堂1 | 五月婷婷小说 | 成人区人妻精品一区 | 91精品福利| gogo人体做爰aaaa | 亚洲中文字幕一区二区 | 在线观看成人网 | 国产精品高潮呻吟久久久久久 | 成人免费毛片片v | 老熟女毛茸茸 | 99999av| 美女扒开腿让男人捅 | 性欧美丰满熟妇xxxx性仙踪林 | 黑人导航| 风流老熟女一区二区三区 | 国产第一网站 | 激情五月婷婷丁香 | 欧美久久久久久久久久 | 黄av网站| 国产毛片毛片毛片毛片 | 国产免费aa | 久久久久久久久久久久久久免费看 | 噜噜噜在线视频 | 男生插女生视频在线观看 | 国产午夜精品久久久 | 男女插孔视频 | 免费一级片在线观看 | 国产精品毛片久久久久久久av | 久热免费在线视频 | av中文一区 | av中文网| 亚洲欧美激情小说另类 | 国产美女无遮挡免费视频 | 日韩一区二区精品 | 色多多黄色 | 国产精品久久久久久亚洲 | 爆乳熟妇一区二区三区霸乳 | 成人精品一区二区三区视频 | 国产黑丝精品 | 素人av在线| 一区不卡av | 亚洲成人视屏 | 欧美少妇xx | 欧美整片第一页 | v在线| 双性人bbww欧美双性 | 男人天堂2024| 日韩久久一级片 | 欧美一级片网址 | 4438亚洲 | 成人精品视频一区二区 | 中文字幕亚洲精品在线观看 |