Example javascript array and all method with example.
Example javascript array and all method with example.
1 Replies, 482 Views
A: An example of a JavaScript array is:
(This post was last modified: 11-06-2023, 01:07 PM by mohan.)
var myArray = [1, 2, 3, 4, 5]; The all() method checks if all elements in an array pass a test (provided as a function). The method returns true if all elements in the array pass the test, otherwise it returns false. Example: function checkPositive(element) { return element > 0; } var array1 = [1, 2, 3, 4, 5]; console.log(array1.every(checkPositive)); // expected output: true |
Users browsing this thread: 1 Guest(s)