Obtain the identification number for my initial asset and use it to refine the identification of my secondary asset

Consider the following scenario with JSON data:

sampledataA = [
  {"id": 1,"employee_id": 1},
  {"id": 2,"employee_id": 1},
  {"id": 3,"employee_id": 1},
  {"id": 4,"employee_id": 2},
  {"id": 5,"employee_id": 2},
  {"id": 6,"employee_id": 2},
  {"id": 7,"employee_id": 3},
  {"id": 8,"employee_id": 3},
  {"id": 9,"employee_id": 3}
]

sampleDataB = [
  {"employee_id": 1, "name":"Name1"},
  {"employee_id": 2, "name": "Name2"},
  {"employee_id": 3, "name": "Name3"}
]

In my controller, I need to extract the employee_ids from sampleDataA and then filter these employee ids against sampleDataB in order to retrieve the corresponding names. Is it feasible to achieve this within the controller?

Answer №1

const id = 1; //value you need to find...
const employeeID = datasetA.find(entry => entry.id === id).employeeID;
const name = datasetB.find(entry => entry.employeeID === employeeID).name;

Does this answer your question?

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

Adjusting the content of a single text box by typing in another

Is it feasible to automatically convert a Nepali date input in one textbox into an English date and display it in another textbox without any page refresh? I have a PHP function that can translate dates between Nepali and English, and I want it to execute ...

"Functionality of public methods in JavaScript plugin seems to be malfunction

Recently, I made the decision to redevelop a jQuery plugin using vanilla JavaScript. However, I have encountered an issue with getting the public methods to function properly. Despite all other logic working correctly, the public methods are not respondi ...

Making a surface-level copy of an array containing nested arrays

I am facing an issue with manipulating child arrays within a parent array. Specifically, I want to manipulate the first element in the first child array without affecting the rest of the arrays. However, my current code is shifting the first elements of al ...

Error occurs when attempting to reference an object from an NPM package

Currently, I'm attempting to utilize the https://github.com/iamcal/js-emoji library for colon-to-emoji conversion. Following the installation of its NPM package, I included <script src="../node_modules/emoji-js/lib/emoji.js" type="te ...

Utilizing a repetitive element as a fresh offspring in the replaceChild() function

const addToCartButtons = document.getElementsByClassName('add-to-cart'); const addToCartButtonsArray = Array.from(addToCartButtons); const increment = document.createElement('img'); increment.setAttribute('src', '/assets ...

React Native formInput Component with Underline Decoration

Utilizing the FormInput element in React Native Elements, I have observed a line underneath each FormInput component. Interestingly, one line appears fainter than the other. https://i.sstatic.net/ZD8CI.png This is how the form looks: <View style={sty ...

Troubles arise when trying to load AngularJS using RequireJS within the application

I am currently developing a NodeJS application that utilizes AngularJS for its front-end. Additionally, I am integrating RequireJS to handle the loading of JavaScript dependencies and then initialize the Angular app. Here is my approach: Inside my HTML fi ...

Sending the child state value to the parent state array

I have successfully implemented the react-select component on a GitHub page, specifically a multiselect component similar to the one found in the example provided at this link. Everything is working as expected, but I am facing an issue when trying to pass ...

What could be the reason for my http request failing to receive a response?

I have successfully implemented multiple routes in my API, but I am encountering issues with the comment system. I am not receiving any response when accessing the URL (node backend) or using Postman. While my server JS code works for POST requests, teams ...

Tips for placing an object within the boundaries of a canvas using three.js

At the moment, I am utilizing the threejs library to design 3D objects. However, I am facing an issue where the object is overflowing outside the canvas if it is too long. You can view my code snippet on JSFiddle. Script import * as THREE from 'https ...

JavaScript, determining variable scope, sequence of evaluating variables

While testing an AngularJS app with Protractor, I have come across a perplexing issue: var counter = 0; redButton.click(); allImages.each(function(element) { element.isDisplayed().then(function(isDispl){ if(isDispl === true){ expec ...

Node.js delete operator not performing as anticipated

Within my node.js express application, I am fetching a user object from the database: const newUser = await User.create({ username, password, email, avatar, }) However, before sending back the response containing the user object, I ...

I encountered a RangeError with code [ERR_HTTP_INVALID_STATUS_CODE] due to an invalid status code being undefined

I have encountered a specific error while running my note-taking app. The error seems to be related to the following piece of code - app.use((err,req,res,next)=>{ res.status(err.status).json({ error : { message : err.message ...

Achieving form validation in Angular through external data binding techniques

I am facing a challenge with my Angular 4 form as the data is being tracked in an injected service, which is necessary for the project. For each input, the code looks like this... <input name="..." [ngModel]='getVal(...)' (ngModelChange)=&ap ...

Sped up object outpacing the mouse pointer

I'm currently developing a drag and drop minigame, but I've encountered an issue with the touch functionality. The draggable function (using only cursor) works flawlessly, however, when I tried to implement touch support for mobile and tablet use ...

Anguar server encountered a startup issue and failed to initialize

My server.js file looks like this: var express = require('express'), api = require('./api'), app = express(); app .use(express.static('./public')) .use('./api', api) .get('*', ...

Advantages and disadvantages of using Jaxer

While I have seen this question asked previously, it has been a while without any satisfactory responses... My attention has been caught by Aptana's Jaxer, and I must say, the concept is quite intriguing. For those unfamiliar with it, here's a ...

Using Content-Disposition in ng-file-upload with AngularJS

Context: I am currently working with ng-file-upload to submit two files separately using ngf-selects along with a Javascript object literal. The problem I'm facing is that when the request is sent, all the parts have their content-disposition set to ...

A mysterious issue arose while trying to retrieve the script (Service Worker)

After disconnecting from the internet, my service worker is generating the following error: (unknown) #3016 An unknown error occurred when fetching the script This is what my service worker code looks like: var version = 'v1' this.addEventLis ...

What steps do I need to take to develop a Django and SvelteKit web application?

While I have experience with Bootstrap and Django, I am new to other frontend frameworks like Angular, React, and SvelteKit. Recently, I decided to give SvelteKit a try but I'm feeling overwhelmed by my lack of familiarity with it. Following the tuto ...