What is the best way to apply dynamic filters on a nested object using Lodash?

Here is the data that I am working with:

 properties: {
  '2': [
    {
      id: "2015-1160312",
      date: "2015-01-23",
      number: 1,
      nature: "Sell",
      value: 310000,
      address_number: 10,
      adresse_code: "ST LINCOLN",
      ZIPCODE: "CO80216",
      number_rooms: 2}
      ],
  '4': [
    {
      id: "2015-1160312",
      date: "2015-01-23",
      nature_mutation: "Sell",
      value: 450000,
      address_number: 15,
      adresse_code: "ST HOOHER",
      ZIPCODE: "CO45216",
      number_rooms: 4
   }
      ]
    }

Additionally, I have a filter object that is dynamically created as follows:

let selectedFilters = {1,2,3};

My goal is to filter out the properties where the "number_rooms" match the items in the selectedFilters array. Based on this example, only the first item should be returned.

Answer №1

If properties are already organized by number_rooms, then there is no need for filtering. Simply cycling through the keys of selectedFilters will provide the necessary information. Here is an example:

Object.keys(selectedFilters).forEach(key => {
   // Accessing properties[key] if it exists will give you the data you require
})

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

With the simple click of a button, I aim to refresh and enhance the appearance of a polygon

My goal is to create a button that, when clicked, causes the gray stripe in the middle to transition to the right. I am not very familiar with HTML, CSS, and JavaScript so I could use some help figuring out how to achieve this effect. Here is a quick illus ...

"Efficiently organizing tasks in AngularJS: Utilize Factories for Submitting and Deleting Functions in

While developing a simple To Do App, I noticed that my Controller was getting cluttered with too much code. This made me realize the need to move some of my functions into factories in order to maintain clean and readable code. Below is my JavaScript code ...

Restrict Scrolling on Large Screens with Bootstrap, Allow Scrolling on Medium or Smaller Screens

I have a website that utilizes the Bootstrap 4 framework (v4.4.1). I implemented CSS properties height: 100% in HTML and body along with overflow: hidden to restrict scrolling and keep the content within the browser window only (I don't have much cont ...

The function contacts.map is not defined

Can someone help me understand why I am getting the error message "contacts.map is not a function"? I am working on fetching data from a contacts array list that I have created. My goal is to display buttons inside a panel. When a button is clicked, the sc ...

Sending data from a bespoke server to components within NextJS

My custom server in NextJS is set up as outlined here for personalized routing. server.js: app.prepare() .then(() => { createServer((req, res) => { const parsedUrl = parse(req.url, true) const { pathname, query } = parsedUrl ...

Issue with React Ref: Invariant Violation when trying to addComponentAsRefTo

I'm encountering an issue while attempting to add a ref to a React component. The error message I'm seeing is as follows: invariant.js:39Uncaught Invariant Violation: addComponentAsRefTo(...): Only a ReactOwner can have refs. You might be adding ...

Mapping various sets of latitudes and longitudes on Google Maps

I am working with multiple latitude and longitude coordinates. var latlngs = [ {lat:25.774252,lng:-80.190262}, {lat:18.466465,lng:-66.118292}, {lat:32.321384,lng:-64.757370}, {lat:25.774252,lng:-80.190262}, ]; The coordinates were ret ...

Challenges of redirecting payments through SSLCommerz

I'm encountering an issue with my code. After making a payment, it redirects to this URL: http://localhost:5173/order/$%7Border._id%7D' order?.\_id is not undefined. However, the page displays an error message stating that the site can' ...

Load the React component asynchronously while waiting for the data to be fetched

My ReactJS component looks like this: import React, {useState} from 'react'; import Plot from 'react-plotly.js'; import {utility} from "./utility"; function Chart() { const [use_data, setData] = useState([]); c ...

Strange Interaction with Nested Divs in CSS Layouts

I am working on a webpage layout and currently it looks like this: https://i.sstatic.net/s4TOb.jpg I am trying to align the purple box inline with the pink box inside the yellow box, which is inside the green box. However, when I change the display proper ...

Mastering the Art of Scrolling

Can someone please tell me the name of this specific scrolling technique? I am interested in using something similar for my project. Check out this example site ...

Record changes in another sheet when Google Spreadsheet is edited

Can anyone provide assistance with a problem in Google Spreadsheet? I am looking to log the name and timestamp when a value in a specific column in the "Venues" sheet is changed. However, I'm having trouble determining if I'm working with the co ...

Navigating through uncharted paths on Express

I am completely lost app.js app.use('/', userRoutes); app.use('/adminID', adminRoutes); app.all('*', (req, res, next) => { next(new AppError(`URL Not Found ${req.originalUrl}`, 404)); }) const ErrorHandler = require(' ...

Update the promise status to reflect any changes

While attempting to modify the button text based on the promise status, I created a custom directive for this purpose. Below is the code snippet for my custom directive: .directive('myDir',function(){ return { scope: { ...

Manipulating values within a multidimensional array using JavaScript

I am attempting to populate a multidimensional array with data from a JSON file. The issue I am facing is that I am unable to update the content in the array: if(j>i && hoursYy == hoursY && secondsX == secondsXx){ wocheArray[i].count = wocheArray[i] ...

Struggling to retrieve a JSON object from an Express and Node application, only receiving an empty result

Can anyone assist me? I'm having trouble with the res.json() function in my code. It seems to work after the first request, but not after the second. Right now, my application is quite simple - it scrapes user data from social media platforms like Twi ...

Is it possible to simultaneously send a JSON object and render a template using NodeJS and AngularJS?

I'm currently facing issues with my API setup using NodeJS, ExpressJS Routing, and AngularJS. My goal is to render a template (ejs) while also sending a JSON object simultaneously. In the index.js file within my routes folder, I have the following s ...

There seems to be an issue with the Url.Action method as it

I'm working with this script: $(function() { $.support.cors = true; jQuery.support.cors = true; $.ajax({ crossDomain: true, type: 'GET', url: 'http://example.com/WCFRESTService.svc/GetCategories&apos ...

Display a comprehensive calendar scheduler within the primefaces layout

I am having trouble displaying the full calendar scheduler on my primefaces center layout. I have added the following .js files to my index.xhtml: <h:outputStylesheet library="css" name="fullcalendar.min.css"/> <h:outputStylesheet library="css" ...

Incorporating Jquery and additional JavaScript libraries into a Firefox extension

Is there a better method to include jquery and other scripts in my Firefox extension? While I know this question has been asked multiple times on SO, none of the responses were very helpful. I attempted using the following code in one of the JS files wher ...