Verifying if any of the entries in a specific index contain a null value

Here is the structure I am working with:

{
  "subs": [
    {
      "status": "1",
      "run_settings": null,
      "ward": "/asda/asd/ada"
      "value": null,
      "name": null
    },
    {
      "status": "0",
      "run_settings": null,
      "ward": "/asda/asd/txa"
      "value": null,
      "name": abc
    }
  ],
  "name": "step"
}

I am trying to verify if any field in one of the indexes within the subs array is null. I attempted the following code snippet:

this.data.subs.map(sub => Object.values(sub).every(x => (x !== null && x !== 'undefined')))

However, this results in [false,false]. While I can add another loop to check for any false values, it seems like there might be a simpler solution. Any suggestions on a more effective way to determine if any field in one of the indexes within the array subs is null?

Answer №1

You may achieve the desired outcome by utilizing Array.some.

The some() function evaluates whether at least one element in the array meets the conditions specified by the provided function, returning a Boolean value.

const data = {
  "subs": [{
      "status": "1",
      "run_settings": null,
      "ward": "/asda/asd/ada",
      "value": null,
      "name": null
    },
    {
      "status": "0",
      "run_settings": null,
      "ward": "/asda/asd/txa",
      "value": null,
      "name": 'abc'
    }
  ],
  "name": "step"
};


const res = data.subs.some(sub =>
  Object.values(sub).every(x => (x !== null && typeof x !== 'undefined')));

console.log(res);

Trust this information proves helpful,

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

What are the semantics behind implementing Basic Authentication in AngularJS and Spring Boot?

Currently going through a tutorial that involves AngularJS and Spring Security. The AngularJS navigation controller triggers an authenticate function upon page load: var authenticate = function(credentials, callback) { var headers = credentials ? { ...

Transitioning from left to right, picture smoothly scrolls into view using Way

I've explored various websites and even attempted to decipher a waypoint guide, but unfortunately, I haven't had any success. The scroll function doesn't seem to be working with the code below. (source: ) Any assistance on this matter would ...

The search function on my blog is not displaying the blogs that have been filtered

I have encountered an issue with my code as I am unable to get any search results from the search bar. const RecentBlogs = ({recentBlogs}) => { const [query, setQuery] = useState("") const filteredItems = (() => { if(!query) return rec ...

What is the best way to provide a static file to an individual user while also sharing its file path

I have integrated jsmodeler (https://github.com/kovacsv/JSModeler) into my website to display 3D models. Currently, users can only select a file using a filepicker or by entering the path in the URL (e.g., http://localhost:3000/ModelView#https://cdn.rawgit ...

When making a JQuery - Ajax get request, I did not receive the "extracts" or "exintro" (summary) property in the response

Lately, I've been working on a small web application that displays search results from Wikipedia on the webpage after entering a search term into a text field. This has been a project that I’ve dedicated a lot of time to. I have configured an ajax g ...

AngularJS's hidden input field is not being properly updated

I am currently using angularjs v1.0.7 and facing an issue with a hidden form field whose value is related to another input value. In the example provided at http://jsfiddle.net/4ANaK/, the hidden field does not update as I type in the text input field. &l ...

Obtain a collection of the corresponding keys for a given value from dictionaries

I'm implementing a function that retrieves a list of keys associated with a specific value in the dictionary. Although I am able to print out the first key successfully, I'm facing difficulties in displaying subsequent keys. I understand that I ...

Calculating the rotation angle of a spinning cylinder in Three.js animations

I'm struggling with this Math problem and my skills are failing me. To see my progress so far, you can view the working example here. After extracting the y and z positions from the rotating cylinder, I've managed to pause the animation when the ...

Can Browserify be used with AngularJS to bundle directive templateUrls using relative paths?

Currently, I am developing a web application using AngularJS and Browserify to bundle my JavaScript files into a single package for use on the webpage. My project structure looks something like this: app |-index.html |-index.js |-bundle.js |-components ...

There was a syntax error when trying to include HTML code and JavaScript actions within a PHP file

My current challenge involves loading dataTables using AJAX in Laravel framework. Here is a snippet of my code: if($posts) { foreach($posts as $r) { $nestedData['name'] = $r->name; $nestedData['email'] = $r->e ...

Error: Unable to set reference. The initial argument includes an undefined value in the 'gender' property of 'Users.ji8A7TkSldfdvieDqGxko9eV3Jy1'

I followed along with a Firebase Web Tutorial on YouTube about adding data to Firebase Database for an account settings tutorial. However, when I tried to implement the code provided, it didn't work. Can anyone offer any assistance? // Code snippet fo ...

Having trouble understanding why the other parts of my header are not displaying

<head> This special function runs when the webpage is loaded. <body onload="myOnload()"> A distinctive div at the top with a unique graphic <div id="header"> <img src="resumeheader.png" alt="Header" style="width:750px;h ...

Looking to prevent editing on a paragraph tag within CKEditor? Simply add contentEditable=false to the

Within my CKEditor, I am in need of some predefined text that cannot be edited, followed by the rest of my content. This involves combining the predefined verbiage (wrapped in a p tag) with a string variable displayed within a specific div in CKEditor. The ...

Exploring the setTimeout function in JavaScript

As I understand it, the setTimeout function creates a new thread that waits for x milliseconds before executing the JavaScript function. setTimeout(functionName, timeInms); My question is: Is there a way to instruct it to run after all other JS on the pa ...

What is the process by which React loads and runs JSX content?

What is the method used to identify and handle JSX code? <script src="src/main.js" type="text/babel"></script> ...

Troubleshooting: Angular version 4.3 Interceptor malfunctioning

I have been trying to implement new interceptors in Angular 4.3 to set the authorization header for all requests, but it doesn't seem to be working. I placed a breakpoint inside the interceptor's 'intercept' method, but the browser didn ...

How can we ensure that the Material-UI <Select> component is as wide as the widest <MenuItem>?

I am attempting to adjust a Mui Select field so that it is the same width as its largest MenuItem. Despite trying to utilize the autoWidth prop on the Select component, I have not been able to achieve the desired result. To better illustrate the issue, I h ...

Creating a new object store in IndexedDB on Windows 8

Encountering issues with creating an object store in IndexedDb while trying to build a Metro app using Javascript. The code snippet below shows my attempt within the 'dbReq.onsuccess' function that is supposed to create the object store upon succ ...

can a computed property be delayed in its calculation?

Within the code snippet below, we can see that in the compPropsIsBtnDigitizePolygonDisabled function, it initially checks if the digitizePolygonInteractions variable is initialized. If it is not initialized, an error will be triggered. During execution, w ...

Tips for providing arguments in the command line to execute a yarn script

Just starting out with JavaScript. I understand that npm allows for passing variables in the command line using process.env.npm_config_key like this: npm run --key="My Secret Passphrase" test:integration How can I achieve the same thing with yarn? I&apo ...