In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
In this article Xiaobian for you to introduce in detail "es6 how to change array data", the content is detailed, the steps are clear, the details are handled properly, I hope this "es6 how to change array data" article can help you solve your doubts, following the editor's ideas slowly in-depth, together to learn new knowledge.
Change the method: 1, the use of splice () method to modify the contents of the original array, the syntax is "array .splice (start position, the number of changes, the modified value)"; 2, the use of subscript to access array elements, and re-assign values to modify the array data, syntax is "array [subscript value] = modified value;"
This tutorial operating environment: windows10 system, ECMAScript version 6. 0, Dell G3 computer.
How does es6 change array data
Method 1: using splice () method
The splice () method changes the contents of the array, adding new elements when the old elements are deleted.
Grammar (Syntax)
Array.splice (index, howMany, [element1] [,..., elementN])
Details of the parameter (Parameter Details)
Index-starts changing the index of the array.
HowMany-an integer indicating the number of old array elements to delete. If howMany is 0, no elements are deleted.
Element1,..., elementN-the element to add to the array. If no element is specified, splice simply removes the element from the array.
Return value (Return Value)
Returns the extracted array based on the passed parameters.
Example (Example)
Var arr = ["orange", "mango", "banana", "sugar", "tea"]; var removed = arr.splice (2,0, "water"); console.log ("After adding 1:" + arr); console.log ("removed is:" + removed); removed = arr.splice (3,1); console.log ("After adding 1:" + arr); console.log ("removed is:" + removed)
At compile time, it will generate the same code in JavaScript.
Output (Output)
After adding 1: orange,mango,water,banana,sugar,tea removed is: After adding 1: orange,mango,water,sugar,tea removed is: banana
Method 2: access the specified element through the subscript
The syntax for accessing array elements and reassigning values:
Array name [specify subscript value] = new value
Examples are as follows:
Var arr = [1Jing 2 Jing 3 Jing 4 Jing 5]; / / declare an array console.log (arr); arr [0] = 0; / / modify the first element and reassign it to 0arr [2] = "A"; / / modify the third element and reassign it to 2console.log (arr)
Output result
After reading this, the article "how to change array data in es6" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, please follow the industry information channel.
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.