Suppose I have a response body of an POST API in angular and its an array of objects it goes like this :
79: {customerId: '61c1b85fa7b16079fe7b5b64', title: 'Mr', phoneNumber: Array(0), jobProfile: 'GOLD', designation: 'Uuuuuuuuuuuu', …}
80: {customerId: '61c1b904a7b16079fe7b5b65', title: 'Mr', phoneNumber: Array(0), jobProfile: 'DIAMOND', designation: 'Player', …}
81: {customerId: '61c1b94aa7b16079fe7b5b66', title: 'Mr', phoneNumber: Array(0), jobProfile: 'DIAMOND', designation: 'Boss', …}
82: {customerId: '61c1b987a7b16079fe7b5b67', title: 'Mr', phoneNumber: Array(0), jobProfile: 'DIAMOND', designation: 'Vvvjkb ', …}
83: {customerId: '61c1bb4ca7b16079fe7b5b68', title: 'Mr', phoneNumber: Array(0), jobProfile: 'DIAMOND', designation: 'Player', …}
84: {customerId: '61c1bbd3a7b16079fe7b5b69', title: 'Mrs', phoneNumber: Array(0), jobProfile: 'GOLD', designation: 'Player', …}
85: {customerId: '61c1bd0ca7b16079fe7b5b6a', title: 'Mr', phoneNumber: Array(0), jobProfile: 'GOLD', designation: 'Player', …}
86: {customerId: '61c1bd4ba7b16079fe7b5b6b', title: 'Mr', phoneNumber: Array(0), jobProfile: 'DIAMOND', designation: 'CEO', …}
87: {customerId: '61c1bf34a7b16079fe7b5b6c', title: 'Mr', phoneNumber: Array(0), jobProfile: 'GOLD', designation: 'HELLO', …}
88: {customerId: '61c1bf79a7b16079fe7b5b6d', title: 'Mrs', phoneNumber: Array(0), jobProfile: 'DIAMOND', designation: 'Vvvvvvvvvv', …}
89: {customerId: '61c1c2b2a7b16079fe7b5b6e', title: 'Mr', phoneNumber: Array(0), jobProfile: 'DIAMOND', designation: 'Hiiii', …}
90: {customerId: '61c1c8c7a7b16079fe7b5b6f', title: 'Mr', phoneNumber: Array(0), jobProfile: 'GOLD', designation: 'CEO', …}
This is the array and it has 1000 something entries , So if I want to iterate over this response body and I want to match a particular customerId so that I can save the customerId in local storage and then get the details of a particular row . How can I do that in angular??
EDIT!! **This is my Code Can you help me please here APP is an interface of which type of data I need in my API **
public getSeacrhCustomer(
aadharId: string,
emails: string ,
pan: string,
phoneNumber: string
){
const postData : App = {
aadharId: aadharId,
emails: emails,
pan: pan,
phoneNumber: phoneNumber,
address: '',
city: '',
country: '',
customerId: '',
dateOfBirth: '',
designation: '',
firstName: '',
jobProfile: '',
lastName: '',
middleName: '',
monthlySalary: '',
passbooks: '',
pinCode: '',
state: '',
title: ''
}
{
return this.http.post('http://localhost:9900/api/v1/customer/search',postData
)
.subscribe(responseData=>
{
const specificCustomer= responseData.find((el: { phoneNumber: string | null; }) => el.phoneNumber=== this.phoneId);
if (specificCustomer) {
var specificCustomerId = localStorage.set('customer', JSON.stringify(specificCustomer.customerId));
}
console.log("Search Customer called from Existing Component!!")
console.log(responseData);
console.log(localStorage.getItem("values"))
console.log(this.phoneId)
});
}
}
Here phoneNumber is coming in API response and I want to check whether it is equal to the phoneId or not if it is equal then I will save the respective customerId connected with that phone number in local storage
Here .find() method is giving an error Property 'find' does not exist on type 'Object'.