Verify that all arrays that are returned consist solely of the value false

console.log(allStatuses);

This variable shows two arrays:

[true, false, false, false, false]

[true, false, false, true, false]

In some cases, additional arrays will be displayed with true/false values.

I am interested in determining whether all the arrays shown contain only false values. If they do, I want to execute a specific action.

Can anyone suggest the most efficient method to achieve this?

The following code snippet is being used for this functionality:

angular.forEach($scope.prefAccount, function(account){
     if (typeof account === 'object') {
          var allStatuses = [];  
          angular.forEach(account, function(alertStatus){
               return allStatuses.push(alertStatus.enabled);
          })
          console.log(allStatuses);
     }                    
});

Answer №1

In order to convert a two-dimensional array into a one-dimensional array, you can utilize the .every and .concat methods.

var allStatuses = [
  [true, false, false, false, false],
  [true, false, false, true, false]
]
allStatuses = [].concat.apply([], allStatuses);

var isFalse = allStatuses.every(function (el) {
  return el === false;
})

console.log(isFalse);

Answer №2

To keep it concise and clear, you can use this version:

allStatuses.every(array => !array.some(Boolean))

If arrow functions are not preferred:

allStatuses.every(function(array) { return !array.some(Boolean); })

In simpler terms:

All arrays in the collection allStatuses must not contain any true values.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips on creating a post that can be viewed exclusively by one or two specific countries

I'm stumped on how to create a post that is visible only to specific countries. How can I code it to determine the user's country without requiring them to make an account? Any advice or hints would be greatly appreciated. ...

Retrieving html element id through jquery for ajax retrieved content

Here is the scenario: I have a list of cities populated in an HTML select tag. When the city is changed, a list of sub-localities is fetched as HTML checkboxes. Now, when the status of the sub-locality checkboxes is changed, I need to extract the labels a ...

Is it possible to define an array initially and assign values to it later on?

When attempting to execute the following code snippet, I encountered an error. Can anyone explain why this operation is not working as expected? int main() { char dessert[5]; dessert = "cake"; printf("My favorite dessert is %s\n", dessert); return ...

Sending information to a web API using the POST method

As a newcomer to Javascript, I have encountered an issue while trying to pass data to the POST method of a web API. Sometimes, I am only receiving values properly for the second response (i.e. requestOptions2), which I suspect is due to the asynchronous na ...

Integrating Bootstrap-vue into your Webpack setup for seamless usage

After beginning a project with vuejs-templates and webpack, I decided to incorporate bootstrap-vue. Now, the challenge is figuring out how to implement a bootstrap button. In my code base, specifically in main.js, I have imported BootstrapVue: import Vu ...

Transfer a single property from a particular object in one array to another array of objects based on a condition (JavaScript ES6)

I have 2 sets of data arrays coming from 2 separate API calls const data1 = [ { name: 'John', age: 30, id: 1, }, { name: 'Sarah', age: 28, id: 2, }, ]; const data2 = [ { status: 'active', ...

The jQuery change event does not fire once the DIV has been rendered, while working with CakePHP

Whenever a room_id is chosen from the drop-down menu, I utilize the JS helper to automatically fill in the security_deposit and room_rate input fields. However, there seems to be an issue where selecting a room_id causes the room_rate_update jQuery change ...

Dealing with errors in AngularJS factory servicesTips for managing errors that occur

Factory code app.factory('abcFactory', function ($http, Config, $log) { var serviceURL = Config.baseURL + '/results'; return{ results:function() { var promise = $http({ method: 'GET&apos ...

Converting JSON data into an array containing individual objects, and inserting a new item into each object

I've been working on retrieving data from a JSON file and successfully creating an array of objects. However, I am trying to add an item to each object in the array simultaneously. Check out my current code: var linklist = []; $.getJSON('links. ...

The <SelectField> component in material-ui is not displaying items properly in ReactJS

I am facing an issue with Material-UI where the items are not showing up. I am trying to display categories of products in a SelectField but it doesn't seem to be working. When I click on the SelectField, no items are displayed. Below is the code for ...

AngularJS ng-repeat is not updating when the state changes

Seeking assistance with an Angular application challenge I'm facing. I have implemented a ng-repeat in my app to display the latest messages stored in an array within a controller named "comunicacion": ng-repeat in comunicacion.html <div class=" ...

Ensure the active pill remains visible upon refreshing the page with Bootstrap 4

Currently, I am in the process of building a website with Bootstrap 4, and I have chosen to use pills for my navigation bar buttons. The issue that I am facing is that whenever I refresh the page while on a different tab, it always redirects me back to the ...

Guide on how to modify the color of a single row within a table with just a click

My table structure is as follows: <table> <tr> <td>A1</td> <td>A2</td> <td>A3</td> <td>A4</td> </tr> <tr> ...

Caution: When using Array.prototype.reduce(), make sure the arrow function returns a value

const filteredParams = [...appliedFilters].reduce((prev, curr) => { if (curr.key !== "multi") return { ...prev, ...curr.selectedValue.params }; return; }, {}); When I run this code, I encounter the following warning message in ...

Tips for creating brief animations

I am currently working with a moving div in JavaScript that continues to move for a period of time after the key is released. I am looking for a way to immediately stop the animation upon releasing the key. The animation is controlled by a switch statemen ...

Refresh an AngularJS table built with Bootstrap to display live data in real-time through the use of ng-repeat

Utilizing a bootstrap table with ng-repeat to populate data, yet encountering issues updating and displaying the table. A custom directive has been created for drag and drop functionality in AngularJS. When a file is dragged and dropped, the information i ...

Moving the words from textArea to each 'ol' element using JavaScript

When a word is entered in the textarea, it should be assigned to a specific class within an 'ol' tag. Each subsequent word will be placed in the next class sequentially. If there are no more words, the remaining classes should remain empty. <! ...

click events in backbone not triggering as expected

It's puzzling to me why this is happening. The situation seems very out of the ordinary. Typically, when I want an action to be triggered on a button click, I would use the following code snippet: events:{ 'click #button_name':'somefun ...

Displaying image titles when the source image cannot be located with the help of JavaScript or jQuery

I am currently facing an issue where I need to display the image title when the image is broken or cannot be found in the specified path. At the moment, I only have the options to either hide the image completely or replace it with a default image. $(&apo ...

Converting a constant character hexadecimal string to an unsigned character in C

I couldn't find any existing implementations, so I decided to write one using sscanf. However, I encountered a problem where the conversion of a const char to an unsigned char in "FFx16" format is not working as expected. The output from printf shows ...