Retrieve object containing all identical fields except for one specific field

Looking for help with filtering a JavaScript object

[
    {
        "comparing_result": "d_sens",
        "event": "Require",
        "master_field": "type_de_donnees",
        "master_field_type": "Select",
        "operator": "=",
        "slave_field": "criticite_de_donnees",
        "slave_field_type": "Select"
    },
    {
        "comparing_result": "d_pers",
        "event": "Require",
        "master_field": "type_de_donnees",
        "master_field_type": "Select",
        "operator": "=",
        "slave_field": "criticite_de_donnees",
        "slave_field_type": "Select"
    },
    {
        "comparing_result": "d_ptry",
        "event": "Not Required",
        "master_field": "type_de_donnees",
        "master_field_type": "Select",
        "operator": "=",
        "slave_field": "criticite_de_donnees",
        "slave_field_type": "Select"
    }
]

I want to filter the object to achieve this:

[
    {
        "comparing_result": ["d_sens", "d_pers"],
        "event": "Required",
        "master_field": "type_de_donnee",
        "master_field_type": "Select",
        "operator": "=",
        "slave_field": "criticite_de_donnees",
        "slave_field_type": "Select"
    },
    {
        "comparing_result": "d_ptry",
        "event": "Not Required",
        "master_field": "type_de_donnees",
        "master_field_type": "Select",
        "operator": "=",
        "slave_field": "criticite_de_donnees",
        "slave_field_type": "Select"
    }
]

I'm struggling to find the right method to merge elements with same properties, except comparing_result. Any suggestions?

Thank you!

Answer №1

From what I gather, the task at hand involves utilizing

objArr.forEach(obj => delete obj.comparing_result)

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

Explore the capabilities of Vue.js by creating multiple JavaScript classes within your application

<div class="container" :class="{ qwerty: !open }" :class="lower? 'left' : 'right'"> Hey there, I've noticed that Vue seems to only allow me to add one class with conditions, as shown in the exam ...

Troubleshooting: Dealing with ng-click and invalid functions

Prior to resolving the issue, I encountered a component (within an HTML template) containing a ng-click that was invoking a nonexistent function. Is there a method to enable a strict mode (similar to 'use strict' in JS) or something equivalent t ...

Display dates using a 24-hour format with Vue and v-calendar

Having trouble configuring my v-calendar datetime picker to display in 24h format. I have been reviewing the documentation but haven't been successful so far: <v-date-picker is-expanded id="match-date-time" v-model="date" mode ...

Unable to make a post using vue.js

I am facing an issue while trying to submit form data using "vue-resource" in my code. The error message I receive mentions a problem with the use of this method alongside vue-cli and vuetify. Error [Vue warn]: Error in v-on handler: "TypeError: this.$h ...

Error: Attempting to access the 'HotelInfo' property of an undefined variable led to an uncaught TypeError

//initiating an AJAX request to access the API jQuery(document).ready(function() { jQuery.ajax({ url:"http://localhost:8080/activitiesWithRealData?location=%22SEA%22&startDate=%2205-14-16%22&endDate=%2205-16-16%22&a ...

What is my strategy for testing a middleware that accepts arguments?

Here is the middleware I am working with: function verifyKeys(expectedKeys: string[], req: Request): boolean{ if (expectedKeys.length !== Object.keys(req.body).length) return false; for (const key of expectedKeys) { if (!(key in req.body)) return ...

Refreshing the page or directly loading it results in a blank screen being displayed

Despite researching various solutions to this common issue, none seem to work for me. Let's dive into it. I've developed a Vue 2 application integrated with Express running on AWS Amplify. When testing the app locally in 'dev' mode (np ...

Removing other objects with Mongoose after an update

I'm facing an issue with my update query in mongoose. I can't figure out why other objects are getting deleted when I only intend to update one specific object. The code is functioning correctly in terms of updating, but it's causing all the ...

Javascript function that sets the opacity to 0

Hello everyone, I'm new to SO and seeking some guidance on improving my post! I have a function that sets the opacity of an element to 0 in order to clear it. While this works fine, it becomes burdensome when dealing with multiple elements that requi ...

The 'click' event is not triggering after adding elements to the DOM using AJAX

$(".btn-close").on('click', function () { alert('click'); var win = $(this).closest("div.window"); var winID = win.attr("id"); $(win).find("*").each(function () { var timerid = $(this).attr("data-timer-id"); ...

Commitment without anticipation of a resolution or rejection

While testing one of my AngularJs Services, I decided to write some Unit tests. Below is a sample code snippet that I have come up with: it('', function(done) { aDocument.retrieveServiceFile(extractedFileFeature) .then(function() { ...

Configuration file stored within the node_modules directory

I have developed a generic npm package that contains my business logic. However, I require access to some information stored in my google cloud storage configuration files. How can I retrieve this data when my package is located within the node_modules fol ...

Can the installation of Canvas be done on a device with the M1 chip?

When attempting to install canvas on a MacBook Pro M1 using the command: npm install --save-dev canvas An error is displayed: npm ERR! code 1 npm ERR! path /Users/xiaoqiangjiang/source/reddwarf/frontend/js-wheel/node_modules/canvas ... (error message con ...

Checking to see if all the users mentioned in the message have been assigned a role

Hello everyone, I'm new to asking questions here so please bear with me. I am trying to retrieve all the users mentioned in a message and check if any of them have a specific role, such as the staff role. Thank you for your help! Edit: Here is the ...

Discover the Phillips Hue Bridge within the operational web application on a separate network

Utilizing the node-hue-api package on a Node.js/Express server to interact with the Hue API, I've developed an admin section of a website exclusively accessible to me for controlling my Hue lights. The functionality works seamlessly in my local develo ...

Sharing session data between controller and view in an Express.js application

When logging in with the code below in the express controller to redirect to the main page: req.session.user = user.userLogin; if (req.session.user=='Admin') { global.loggedAdmin = user.userLogin; } else { global.loggedUser = user.us ...

Receiving unexpected results when returning a function within a React hook

I'm currently working on developing a custom React hook that will provide users with a function to execute. This hook is designed to generate a function internally. Check out this simplified example // fetch.js import { useEffect, useState} from &qu ...

Keep the sub-menu in a kendo context menu from closing until the user either hovers over another menu item or clicks outside of the current item

Please take a look at this example: Due to the small size of sub-items, the sub-menu closes quickly when hovering over the menu and losing focus. My goal is to keep an opened sub-menu from closing until the user hovers over another menu item or clicks on ...

Troubleshooting problem with input and textarea losing focus in Ajax requests

Experiencing an issue with submitting information using ajax. For instance, there are 20 rows. When a row is clicked, it displays all details about services. $('tr').click(function() { var servicesUpdateId = $(this).attr('data&a ...

Tips for organizing your JSON Structure within ReactJs

In the given example, I have a JSON structure with information about different airlines. The Airline Name is dynamic and we need to separate the JSON into an expected array format. const arr = [ { Airline: "Goair", Departure: "01:50" ...