1. Array.at()Function : Accepts an integer value and returns the item at that index, both positive and negative integers are allowed. Negative integers count from the last item in the array. Syntax : Array.at(index) Parameters : index: The index (position) of the array element to be returned. Relative indexing from the end of the array is supported when a negative index is passed; that is, if a negative number is used, the returned element will be found by counting backwards from the end of the array. Return value : The element in the array that matches the given index. Returns undefined if the given index is not found <script type="text/javascript"> var arr = [1,2,3,4,5]; var newarr = arr.at(-1); console.log(newarr); // 5 var newarr = arr.at(3); console.log(newarr); // 4 </script> 2. Array.copyWithin()Function : Shallowly copy part of an array to another position in the same array and return it without changing the length of the original array. Syntax : parameter: 0 is the index of the basis, and the sequence is copied to this position. If it is a negative number, target will be counted from the end. If target is greater than or equal to arr.length, no copying will occur. If target follows start, the copied sequence will be modified to fit arr.length. 0 is the base index, the starting position from which to start copying elements. If negative, start will count from the end. If start is omitted, copyWithin will start copying from 0. 0 is the base index, starting at the end position of the copied elements. copyWithin will copy to that position, but not including the element at end. If negative, end will count from the end. If end is omitted, the copyWithin method will copy to the end of the array (default is arr.length) <script type="text/javascript"> var arr = [1,2,3,4,5]; var arr2 = arr.copyWithin(-2) console.log(arr2); // [1, 2, 3, 1, 2] var arr3 = arr.copyWithin(0, 3) console.log(arr3); // [4, 5, 3, 4, 5] var arr4 = arr.copyWithin(0, 3, 4) console.log(arr4); // [4, 2, 3, 4, 5] var arr5 = arr.copyWithin(-2, -3, -1) console.log(arr5); // [1, 2, 3, 3, 4] </script> 3. Array.entries()Function : Returns a new Array Iterator object that contains the key/value pairs for each index in the array. Syntax : Return value : A new Array iterator object. Array Iterator is an object. Its prototype (__proto__:Array Iterator) has a next method that can be used to traverse the iterator to obtain the [key, value] of the original array. <script type="text/javascript"> var array1 = ['a', 'b', 'c']; var iterator1 = array1.entries(); console.log(iterator1.next().value); // expected output: Array [0, "a"] console.log(iterator1.next().value); // expected output: Array [1, "b"] </script> 4. Array.fill()Function : Fill all elements in an array from the start index to the end index with a fixed value. The ending index is not included. Syntax : arr.fill(target[, start[, end]]) parameter :
Return value : the modified array <script type="text/javascript"> var array1 = [1, 2, 3, 4]; // fill with 0 from position 2 until position 4 console.log(array1.fill(0, 2, 4)); // expected output: [1, 2, 0, 0] // fill with 5 from position 1 console.log(array1.fill(5, 1)); // expected output: [1, 5, 5, 5] console.log(array1.fill(6)); // expected output: [6, 6, 6, 6] </script> 5. find()Function: Returns the value of the first element in an array that satisfies the provided test function. Otherwise returns undefined. Syntax: parameter:
Return value: The value of the first element in the array that satisfies the provided test function, otherwise it returns undefined. <script type="text/javascript"> var array1 = [5, 12, 8, 130, 44]; var found = array1.find(element => element > 10); console.log(found); // 12 </script> SummarizeThis article ends here. I hope it can be helpful to you. I also hope that you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: MySQL takes out the comma-separated values from a field to form a new field
>>: Detailed tutorial of pycharm and ssh remote access server docker
First, a common question is, what is the relation...
A few days ago, when I was working on a requireme...
Download and installConfigure environment variabl...
Overview There are many form requirements in the ...
Table of contents Conclusion first question Solut...
Whitelist rule syntax: BasicRule wl:ID [negative]...
Today, in the practice of vue3+vite project, when...
When we package the webpackjs file, we introduce ...
Web Server 1. The web server turns off unnecessar...
Azure Container Registry is a managed, dedicated ...
1. Create a table CREATE TABLE `student` ( `id` i...
MYSQL version: MySQL Community Server 5.7.17, ins...
Nginx (engine x) is a high-performance HTTP and r...
Table of contents Logical Layering Separate busin...
When the height attribute of Text is defined, the ...