In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces whether the length of the array in JavaScript can be changed, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
JavaScript array length can be changed, methods: 1, by changing the value of the array length attribute to change the array length, syntax "arr.length= length value"; 2, the use of unshift (), shift (), splice () and other methods to add or delete array elements to change the array length.
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
The array length in JavaScript can be changed.
The length attribute of the JavaScript array is variable, and we can change the length of the array by changing the value of the length attribute.
Var arr=; / / an array containing 8 values arr [xss_clean] (arr.length); / / displays the array length 8arr.array 10; / / increases the length of the array [xss_clean] (arr.length); / / the array length has changed to 10.
Also, the length of the array changes as the element increases or decreases. Example:
Var arr= [98 arr.length 76]; / / Array containing 5 values [xss_clean] (arr.length); / / display array length 5arr [15] = 34; / / add elements, use index 15, assign to 34alert (arr.length); / / display array length 16
We can use push (), pop (), unshift (), shift (), splice () and other methods to add or remove array elements to change the array length. Example:
Var arr = [0]; / / define the array console.log (arr.length); arr.unshift (1Power2); / / add two elements at once console.log (arr.length); arr.shift (0); / / delete 1 element console.log (arr.length)
Output result:
Thank you for reading this article carefully. I hope the article "whether the array length in JavaScript can be changed" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.