In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Today, I would like to share with you how es6 takes the relevant knowledge points of the first few elements of the array. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look.
Es6 to take the first few elements of the array of two methods: 1, use splice () to intercept array fragments, you can get the first N array elements, syntax "array object .splice (0Magin N)"; 2, use slice () to intercept array fragments, syntax "array object .slice (0Magine N)", you can get the first N array elements.
The operating environment of this tutorial: windows7 system, ECMAScript version 6, Dell G3 computer.
In es6, you can intercept an array and get the first few elements of the array using the following two methods
Splice ()
Slice ()
1. Use splice () to intercept the array
The splice () method can add elements, delete elements, or intercept array fragments. When you delete an element, the deleted array fragment is returned, so you can use the splice () method to intercept the array fragment.
Example 1: intercept the first two elements of the array
Var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"]; console.log (fruits); var citrus = fruits.splice (0 citrus 2); console.log ("the first two elements of the array:" + citrus)
Example 2: intercept the first three elements of the array
Var citrus = fruits.splice (0P3); console.log ("the first three elements of the array:" + citrus)
2. Use slice () to intercept the array
The slice () method is similar to the splice () method, but it can only intercept the elements of the specified section of the array and return the subarray. The method contains two parameters that specify the subscript at the start and end of the intercepted subarray, respectively.
You only need to set the first parameter to 0 and the second parameter to the specified number of N digits to get the first N elements of the array.
Var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"]; console.log (fruits); console.log ("the first element of the array:" + fruits.slice (0jue 1)); console.log ("the first 2 elements of the array:" + fruits.slice (0jue 2)); console.log ("the first 3 elements of the array:" + fruits.slice (0jue 3))
These are all the contents of the article "how to fetch the first few elements of an array by es6". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to 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.