Technicalarticles
<script>// JavaScript to illustrate // lastIndexOf() method function isGreaterThan5(element, index, array) { return element > 5; }function func() { // Original array var array = [2, 5, 8, 1, 4]; // Checking for condition in array var value = array.some(isGreaterThan5); document.write(value); }func(); </script>true
<script>// Original array var numbers = [88, 50, 25, 10];// Performing reduce method var sub = numbers.reduce(geeks);function geeks(total, num) { return total - num; }document.write(sub) </script>3
<script> // Original array var numbers = [4, 9, 16, 25]; // Performing map method var sub = numbers.map(geeks); function geeks() { return numbers.map(Math.sqrt); } document.write(sub)2 3 4 5
<script> // JavaScript code for every() function function ispositive(element, index, array) { return element > 0; } function func() { var arr = [ 11, 89, 23, 7, 98 ]; // Check for positive number var value = arr.every(ispositive); document.write(value); } func(); </script>true
<script>//Original array var arr = [ [11, 89], [23, 7], 98 ];// Performing flat method var geeks = arr.flat();document.write(geeks) </script>11,89,23,7,98
<script>const myAwesomeArray = [[1], [2], [3], [4], [5]]var geeks = myAwesomeArray.flatMap(arr => arr * 10) console.log(geeks); </script>10、20、30、40、50
<script>function isPositive(value) { return value > 0; }function func() { var filtered = [112, 52, 0, -1, 944] .filter(isPositive); document.write(filtered); }func(); </script>112、52、944
<script>var array = [ 10, 20, 30, 110, 60 ];function finding_index(element) { return element > 25; }document.write(array.findIndex(finding_index)); </script>2
<script>// Input array contain some elements. var array = [10, 20, 30, 40, 50];// Function (return element > 10). var found = array.find(function(element) { return element > 20; });// Printing desired values. document.write(found); </script>30
<script>// JavaScript code for fill() function function func() { var arr = [1, 23, 46, 58]; // Here value = 87, start index = 1 and // and last index = 3 arr.fill(87, 1, 3); document.write(arr); }func(); </script>1,87,87,58
<script> function func() { // Original array const items = [1, 29, 47]; const copy = []; items.forEach(function(item){ copy.push(item*item); }); document.write(copy); } func(); <script>1,841,2209
<script>// Original array var numbers = [88, 50, 25, 10];// Performing sort method var sub = numbers.sort(geeks);function geeks(a, b) { return a - b; }document.write(sub) </script>10、25、50、88
<script>// JavaScript code for concat() function function func() { var num1 = [11, 12, 13], num2 = [14, 15, 16], num3 = [17, 18, 19]; document.write(num1.concat(num2, num3)); } func(); </script>11,12,13,14,15,15,16,17,18,19
<script> // Taking input as an array A // having some elements. var A = [ 1, 2, 3, 4, 5 ]; // Include() function is called to // test whether the searching element // is present in given array or not. a = A.includes(2) // Printing result of function. document.write(a); </script>true
<script>
function func() {
//Original Array
var arr = [34, 234, 567, 4];
document.write("Original array: " + arr);
//Reversed array
var new_arr = arr.reverse();
document.write("<br>Newly reversed array: ");
document.write(new_arr); } func();
<script> 原始数组:34、234、567、4
新反向阵列:4、567、234、34
DO U LIKE?