Steps for eliminating empty values from the JSON data

How can I eliminate the properties that have null values in the following input data?


var data = [
        { "Id": "parent", "Function": "Project Management", "Phase": "(Null)" },
        { "Id": "1", "Function": "R&D Team", "Phase": "parent" },
        { "Id": "2", "Function": "HR Team", "Phase": "parent" },
        { "Id": "3", "Function": "Sales Team", "Phase": "parent" },
        { "Id": "4", "Function": "Philosophy", "Phase": "1" },
        { "Id": "5", "Function": " Organization", "Phase": "1" }
     ];

Answer №1

If you want to achieve this, follow these steps:

data = data.map(object => Object.keys(object).reduce((previous, property) => {
  // You have the option to look for '(Null)', null or any other type of value here
  if (object[property] !== '(Null)') {
    previous[property] = object[property]
  }
  return previous
}, {}))

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

performing dual functions within a single click event handler

Is there a way to simultaneously execute 2 functions? In the following code snippet, I am trying to capture the id of the parent Div with the onclick event and then trigger a function using that id. <div id="selDe"> <input type="radio" class="ger ...

Best practice for entering events in callback

Recently, I delved into Angular because I anticipate needing to use it down the line. My current focus is on studying components communication, particularly from child to parent. I came across various methods of achieving this. In each example, the ChildC ...

Determining the percentage between two elements using Bootstrap 4's range slider

I've been searching everywhere but haven't found a solution. I am trying to implement Bootstrap 4.5's range slider to distribute the % difference between Client and Company, ranging from 1% to 100%. However, I am struggling with the jquery/j ...

Extract information from various JSON files and save it to the database

As a newcomer in the realm of Python, I find myself engrossed in a project that requires me to extract data from various JSON files and store it in a Postgresql database. These JSON files all originate from the same website: However, they contain distinct ...

What is the method for retrieving all elements, regardless of duplicative data?

I need assistance with a project in which I am attempting to extract brand names and prices from a website. Below is the code I am currently using: List<WebElement> list_of_products = driver.findElements(By.xpath(loc.getProperty("brandName" ...

Upgrading to React Router v6: Implementing Loader Functions with Context API

Having issues implementing loaders in React-Router V6 while making a request for a page through a function located in the context file. Unfortunately, I can't access the context from main.js where the router is defined. Main.js import ReactDOM from & ...

When using Loopj to perform a Put or Post request with basic authentication, the response may sometimes be null

In an effort to utilize Loopj for synchronous put and post calls from an HTTP utility class, the code utilizes a synchronous client within an AsyncTask. Certain UI interactions heavily rely on the JSON response, hence the AsyncTask is responsible for man ...

What is the best way to extract all of the JSON data from Firebase using a web platform?

As a newcomer to Firebase and noSQL databases, I'm encountering difficulties in extracting all the JSON data from the database. Although I've gone through the firecast tutorials and understand how to retrieve specific values by referencing the da ...

NodeJS experiencing a hitch in the image upload process

I am currently working on a Node code snippet that is used for uploading images. The images I am dealing with have sizes ranging from 10 to 200K, so they are relatively small in size. However, the issue I am facing is that Node seems to get stuck process ...

Verify whether the outcome is a blank string

Recently, I generated a JSON file using a jq command and the structure of the file is shown below: [ { "description": "", "app": "hello-test-app" }, { "description": &qout;", &quo ...

Issues with decoding Json Data

While attempting to parse a JSON and fetch data, I encountered an issue where the result appears to be in XML format instead of JSON. Oddly enough, when checking with JSONLint and Postman, everything looks fine. The code snippet I am currently using is as ...

Tips for effectively passing navigation as props in React Navigation with Expo

How can I correctly pass navigation as props to another component according to the documentation? The navigation prop is automatically provided to each screen component in your app. Additionally, To type check our screens, we need to annotate the naviga ...

Display subnavigation HTML when hovering over the navigation bar

I am in the process of creating a website that features a top navbar. When I hover over one of the nav-items, a sub-nav drops down. Currently, I have implemented a JavaScript/ajax function where clicking on a nav-item displays another HTML page in my subna ...

Encountering a 'Cannot use string as a HASH ref' error message while attempting to decode JSON in Perl using the JSON

Whenever I execute the following code: use strict; use JSON; $json_ref = $json->decode($json_data); After this, my $json_ref structure contains strings as hash refs. To visualize this, I use Data::Dumper like so: print STDERR "JSON: " . Dumper($json ...

Tips for updating the HTTP Request URL using an Angular 6 interceptor

In my current project, I am utilizing an Angular app to communicate with a back end API endpoint using the HTTP module's get/post methods. Recently, I came across another Angular app that cleverly hides the actual API endpoint and replaces it with a d ...

Having trouble transforming JSON into an array using Angular.js

Hello there, I'm currently facing some issues with Angular. I've made a request using $http and received a JSON response like: {"y":"1","a":"0"} I need to convert it into an array format like: {y: 1, a: 0} I've tried using angular.fromJs ...

Troubleshooting issue: Unable to display data using *ngFor in Angular 4

Currently, I am developing an application that utilizes HttpClient to fetch data from a local JSON file. The JSON file contains images and descriptions, with the images also being local. While I am able to successfully log the data in a local array, I am e ...

Retrieving a specific value from a data object using Javascript

Having a data object, I am looking to extract a specific value from it. When attempting to output the data: console.log(data); I receive an object resembling the one shown in the image below : https://i.sstatic.net/OPhgH.png The issue lies in my at ...

What is the best way to combine two parameters using href?

I am having an issue with my kendo grid. I am trying to pass two parameters from the client side using an anchor tag and href, but I keep getting a syntax error. Can someone help me figure out the correct way to pass variables using href? Here is my confi ...

What is the proper way to add properties and functions to a ref in JavaScript?

Is it possible to embed properties and functions within a ref? For instance, consider this scenario: const MyComponent = () => { const [loading, setLoading] = React.useState(false) const onTest = () => 'works' return ( ...