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

Guide to dynamically resizing the Monaco editor component using react-monaco-editor

Currently, I am integrating the react-monaco-editor library into a react application for viewing documents. The code snippet below showcases how I have set specific dimensions for height and width: import MonacoEditor from 'react-monaco-editor'; ...

Sort products by category upon loading of the category page in Angular

I am currently working on an angular web application that showcases various categories from the category model. The category model is linked as a foreign key to the products model. My goal is to implement a feature where users can filter and view all the p ...

Executing test units in Angular

While setting up unit tests for my Angular app, I expect the ngInit function to be called. Component.ts: ngOnInit() { this.topToolBarService.change.subscribe(customer => { this.filter.customerid = customer; this.customerid = customer; ...

Guide to incorporating the useEffect hook within a React Native View

I am trying to use useEffect within a return statement (inside a Text element nested inside multiple View elements), and my understanding is that I need to use "{...}" syntax to indicate that the code written is actual JavaScript. However, when I implement ...

Unidentified file: Error reading property 'filename'

I have a function that retrieves the file name. The file name is displayed in an input field, but the background color of the input field is only visible when a file is selected and the file name is populated there. I would like the background color to b ...

Should the RxJS interval() function be employed to receive live server updates?

In my Angular application, I implemented this code to continuously check for updates. export class RealTimeComponent { products$:any; constructor(private service: ProductService){} ngOnInit(){ this.products$ = interval(5000) .pipe( ...

Creating and verifying variables in a template

I'm currently exploring how to assign a variable when a specific value/string is identified in an ngFor loop, and then exhibit a div within the same template upon identification... When the condition indicated in the code snippet below holds true, I ...

Firebase allows for the updating of an object within a nested array

Within Firestore, I have a Document that includes a property named "items" which is of type array. This array consists of ShoppingItem objects with the specified structure: export class ShoppingItem { id?: string; name: string; checked = false; } To ...

No response data being displayed after Angular post request

After sending a POST request via Postman, I received the expected response with a status of 400. However, when I tried sending the same request using Angular's http.post in the browser, I only received a 400 error without any response data. https://i ...

How to reference 'this' within a d3 callback when using Angular 7

In an Angular directive, I am trying to access a class-level variable inside a callback function. To achieve this, I used an arrow function but the 'this' keyword is still not pointing to the directive. this.itemRects.selectAll('rect') ...

Drawing a real-time curve using Phaser 3

After reading the article at the following link, I am attempting to create a dynamic curve showing where a bullet intersects with the land in my game before firing. Any suggestions or ideas on how to achieve this would be greatly appreciated. Thank you. L ...

Removing a field from a collection using firebase-admin: Tips and tricks

I currently have a collection stored in Firebase Realtime Database structured like this: My requirement is to remove the first element (the one ending with Wt6J) from the database using firebase-admin. Below is the code snippet I tried, but it didn' ...

How to conditionally import various modules in Next.js based on the environment

Having two modules 'web,ts' and 'node.ts' that share similar interfaces can be challenging. The former is designed to operate on the client side and edge environment, while the latter depends on node:crypto. To simplify this setup, I a ...

Factory Pattern Utilizing Enum for Field Population

Struggling to find a solution for setting default values for instances created by the factory method createLetterMap... I don't think the problem lies in 'How to loop over enums' because it seems impossible due to types not being available ...

Is there a way to modify a component's CSS by using a global CSS class name in Angular?

We have implemented a system where a class on the html element determines whether the user is in dark or light mode of the application. <html class="dark-mode"></html> This class is dynamically added using Renderer2 in a service that detects ...

How can you extract the text content within component tags that is neither a component nor an HTML tag?

For illustration purposes, consider the following example: var ItemComponent = ng.core.Component({ selector: "item", inputs: ["title"], template: "<li>{{title}} | <ng-content></ng-content></li>", }).Class({ construc ...

Demonstrating the transformation of child elements into parent elements through angular 6 ngFor

I have a JSON array dataset where each object may contain nested arrays. In order to display the inner nested array elements as part of the parent array using Angular's NgFor, I need to format the input like this: [{ 'id': 1, 'tit ...

Ways to resolve the issue with the Argument of type 'Date[]' not matching the parameter type '(prevState: undefined) in React

I've encountered an issue while trying to construct my project. The error message reads as follows: Argument of type 'Date[]' is not assignable to parameter of type '(prevState: undefined) Here's the excerpt of the code in questio ...

How to access a variable from outside a promise block in Angular

Is there a way to access a variable declared outside of a promise block within an Angular 6 component? Consider the following scenario: items: string[] = []; ngOnInit() { const url='SOME URL'; const promise = this.apiService.post(url ...

Angular - Customizing button bindings for various functions

As a newcomer to Angular and TypeScript, I am faced with the task of creating a customizable button that can display text, an icon, or both. For example: button-icon-text-component.html <button> TEST BUTTON </button> app.component.html & ...