Comparing strings with data in objects using Angular

all.

I have a query. What is the optimal method for comparing data?

For instance, if you have a constant response = 225235743;

And I aim to locate and exhibit all data in an object with the same ID as the one in this response.

This needs to be resolved in typescript, not HTML using loops or conditions...

   {
  "data" : [
    {
      "L_PHONE_NUMBER" : "bb",
      "L_DELETED" : "",
      "UID" : 1,
      "L_ADDRESS" : "addressb",
      "L_NIGHT_HOURS_TO" : "",
      "L_ACCOUNT_ID" : "225235743",
      "L_NIGHT_HOURS_FROM" : "",
      "L_DEALER_ID" : "",
      "L_BRANCH_NAME" : "Branch 1b",
      "L_ID" : "arbvgBwzNc",
      "L_REGION_ID" : "",
      "L_JOB_DELAY" : "bb"
    },
    {
      "L_PHONE_NUMBER" : "8885577910",
      "L_DELETED" : "",
      "UID" : 2,
      "L_ADDRESS" : "640 S Hathaway St, Santa Ana, CA 92705",
      "L_NIGHT_HOURS_TO" : "12:00:00",
      "L_ACCOUNT_ID" : "syWESGISHx",
      "L_NIGHT_HOURS_FROM" : "00:00:00",
      "L_DEALER_ID" : "QvUuWqPhRG",
      "L_BRANCH_NAME" : "Santa Ana, S Hathaway St",
      "L_ID" : "Dmx3ma5dnI",
      "L_REGION_ID" : "",
      "L_JOB_DELAY" : "15"
    },
    ...

Apologies beforehand for the triviality of my question, but I've pondered over this solution for quite some time.

Answer №1

Utilizing the filter technique enables you to locate data with matching IDs

const response = 225235744;

const info = {
  "info": [{
      "L_PHONE_NUMBER": "bb",
      "L_DELETED": "",
      "UID": 1,
      "L_ADDRESS": "addressb",
      "L_NIGHT_HOURS_TO": "",
      "L_ACCOUNT_ID": "225235743",
      "L_NIGHT_HOURS_FROM": "",
      "L_DEALER_ID": "",
      "L_BRANCH_NAME": "Branch 1b",
      "L_ID": "arbvgBwzNc",
      "L_REGION_ID": "",
      "L_JOB_DELAY": "bb"
    },
    {
      "L_PHONE_NUMBER": "8885577910",
      "L_DELETED": "",
      "UID": 2,
      "L_ADDRESS": "640 S Hathaway St, Santa Ana, CA 92705",
      "L_NIGHT_HOURS_TO": "12:00:00",
      "L_ACCOUNT_ID": "syWESGISHx",
      "L_NIGHT_HOURS_FROM": "00:00:00",
      "L_DEALER_ID": "QvUuWqPhRG",
      "L_BRANCH_NAME": "Santa Ana, S Hathaway St",
      "L_ID": "Dmx3ma5dnI",
      "L_REGION_ID": "",
      "L_JOB_DELAY": "15"
    },...]
};
const result = info.info.filter(d => d.L_ACCOUNT_ID == response);
console.log(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

What is the best way to retrieve the final entry from a JSON file while using json server with Angular?

I'm currently working with a JSON file where I am making post requests followed by get requests. My goal is to retrieve the latest record in each get request after submitting a post request. For example: [ { "id": 1, "title&qu ...

The Typescript hello world example encounters an issue with Karma

Recently, I encountered an issue while working on a TypeScript project with Jasmine and Karma. It seems that Karma is unable to execute the compiled unit tests due to an error showing up in Chrome: Uncaught ReferenceError: define is not defined To illust ...

A guide on implementing Angular-DataTable within a TypeScript project

Hey everyone, I'm currently working on a TypeScript and Angular application. To create a data table, I decided to use Angular-DataTable. After creating a sample application using it, I added the following code to my Controller: constructor(protecte ...

Encountering a glitch when attempting to run Bootstrap 4 on an Angular 6 Application

After installing Bootstrap 4 using Angular CLI, I encountered an error when running the application. To resolve this issue, I made changes to the angular.json file: "styles": [ "src/styles.css", "../node_modules/bootstrap/dist/css/bo ...

Tips for validating form input upon submission in Angular 6

Within my Angular application, I have successfully implemented form validators. However, I am aiming to trigger form validation specifically upon submission. This means that when the user clicks on the submit button and the form is invalid, the errors indi ...

What is the best way to create a calendar that displays every day in a single row?

Is it possible to create a calendar with all days in one row? I've been searching for a solution to this problem without any luck. It's surprising that I haven't found a clear answer or explanation on how to achieve this. I'm sure man ...

There was an unfortunate parsing failure in the module: An unexpected token appeared at position 4

I need help adding the FULLCALENDAR feature to my Angular v14 project. Despite going through all the necessary setup steps, I encountered an unexpected error. Can anyone provide guidance on how to resolve this issue? package.json "@fullcalendar/angul ...

After pressing the login button, my intention is to transition to a different page

I am relatively new to web development and working with angular. I have a login component that, upon hitting the LOGIN button, should redirect to another component on a different page. However, currently, when I click the button, it loads the data of the o ...

What is the correct way to utilize Array.reduce with Typescript?

My current approach looks something like this: [].reduce<GenericType>( (acc, { value, status, time }) => { if (time) { return { ...acc, bestValue: valu ...

What is the best way to define an event binding statement in the Angular code rather than within the template?

Is it possible to define the event binding statement directly in the code (rather than in the template)? I am trying to dynamically create a menu, and while I can achieve this with routes (since they are strings), using event names seems to be more challe ...

The panning functionality on Android devices within the Firefox browser is currently experiencing issues with both panstart and pan

Currently, I am collaborating on an Angular7 project and utilizing hammerjs version 2.0.1. One of the tasks at hand is to allow panning functionality on a map for mobile devices. After testing on various android devices, I noticed that it performs well on ...

"Trying to create a new project with 'ng new xxx' command resulted in error code -4048

Whenever I execute 'ng new projectName' in vs code, I encounter the following issue. ng new VirtualScroll ? Would you like to add Angular routing? Yes ? Which stylesheet format would you like to use? SCSS [ http://sass-lang.com ] CREATE Vir ...

Transforming Uint8Array into BigInt using Javascript

I've come across 3 different ways to convert a Uint8Array to BigInt, but each method seems to produce varying results. Can someone clarify which approach is correct and recommended? Utilizing the bigint-conversion library. The function bigintConversi ...

Issue with parsing JSON data in AgGrid

I'm currently utilizing Ag-grid within my Angular project. The rowData is populated with data from a JSON file stored in the assets folder, which is fetched using HttpClient. However, I'm encountering an issue where the data fails to load and an ...

Detecting URL changes on new windows in Angular Typescript: How to do it?

I am currently working with the updated version of Angular 6. My task involves opening a new browser window based on user input, which includes a specific return URL. After the return URL is fully loaded, I need to access and extract a particular element f ...

How Angular can fetch data from a JSON file stored in an S3

I am attempting to retrieve data from a JSON file stored in an S3 bucket with public access. My goal is to parse this data and display it in an HTML table. http.get<Post>('https://jsonfile/file.json').subscribe (res => { cons ...

Angular with NX has encountered a project extension that has an invalid name

I am currently using Angular in conjunction with nx. Whenever I attempt to execute the command nx serve todos, I encounter the following error: Project extension with invalid name found The project I am working on is named: todos. To create the todos app ...

Obtain a collection of lists stored in Firebase

As I work on creating an Ionic app with a Firebase database, my data structure in Firebase looks like the image below. I am utilizing angularfire2 to retrieve this data: https://i.stack.imgur.com/5akQf.png While I have successfully obtained the list of pa ...

Choose only the options that are present in both arrays

I am working on creating a multiple select feature that displays all nodes, but only checks the ones that are present in 2 arrays. My front end is developed using Angular 8 and TypeScript. private mountSelect(nodesInRelation, lineApiKey) { console.lo ...

Having trouble building a new project with Angular-cli v.6?

I recently installed Angular CLI version 6 and created a new project following these steps: npm install -g @angular/cli@^6.0.0 ng new my-app cd my-app npm install npm build However, I encountered an error during the build process with the following messa ...