Extract Value from an Array of Objects in Angular 2

Is there a way to extract values from this array? I am looking to retrieve the value of firstPersonName from each object.

https://i.sstatic.net/CdfyC.png

This is what I have attempted so far:

var rest = email.map(a => {
    a.firstPersonEmail;
});
console.log(rest);

However, the result I am getting is shown below:

https://i.sstatic.net/BesUy.png

Any assistance on this matter would be greatly appreciated. Thank you :)

Answer №1

If you're looking for assistance, consider this:

var rest = email.map(a => {
  return a.firstPersonEmail;
});
console.log(rest);

or

var rest = email.map(a => a.firstPersonEmail);
console.log(rest);

const email = [
  {id:1, firstPersonEmail: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="591336313719343830357734383035">[email protected]</a>"},
  {id:2, firstPersonEmail: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="470d282f2975072a262e2b692a262e2b">[email protected]</a>"},
  {id:3, firstPersonEmail: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a4eecbccca97e4c9c5cdc88ac9c5cdc8">[email protected]</a>"}
];

const emptyEmail = [];

console.log(`Email length: ${email.length}`);
console.log(`Empty Email length: ${emptyEmail.length}`);

const rest = email.map(a => a.firstPersonEmail);
const emptyRest = emptyEmail.map(a => a.firstPersonEmail);

console.log(rest);
console.log(emptyRest);

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

How can you use $in and $or in a MongoDB query to search for specific values?

Here is an array of words: var norm = [ 'may', 'funny', 'top funny', 'dinner', 'dog', 'hello', 'flo', 'sake', 'hai', 'video', 'rhym ...

What steps should I take to ensure the privacy of this React Layout?

To ensure only authenticated users can access the layout component, we need to implement a check. const router = createBrowserRouter([ { path: "/", element: <Layout />, children: [ { path: "/", ...

VueJS restricts the selection of only one checkbox based on its class name

I am working with a group of checkboxes: <div class="options"> <input type="checkbox" value="10" v-model="choices"> <input type="checkbox" value="30" v-model="choices"> <div class="group"> <input type="checkbox" value= ...

The function String.match.length will return an array, so make sure to expect an integer value

I have been working on developing a function that is capable of counting the matches of each letter of the alphabet in a given string. Once I obtain these counts, my goal is to store them in an associative array for easy reference. However, the issue aris ...

Finding out which side of a cube has been clicked---Let's identify the side

Currently, I am in the process of developing a navigation menu and I am looking for a way to detect which side the user has clicked. Is it possible to achieve this using raycasting or is there an alternative method that would work better? If you require i ...

Unable to configure raycaster layers within Three.js framework

While attempting to configure the raycaster layer to only cast on a single layer, as outlined in the threejs documentation: - I encountered the following error Uncaught TypeError: Cannot read properties of undefined (reading 'set') What could b ...

Dynamically cycle through sublists and save their contents

Similar Question: How to Flatten an Irregular List of Lists in Python Is there a more efficient way to save the results without explicitly writing out the name of each sublist? Please note that the numbers used in the arrays are just placeholders for ...

The maximum value of the slider corresponds to the total number of elements in the array

As I work on constructing a Material UI Slider, I have a specific requirement. I want the maximum value of my slider to dynamically adjust according to the number of items in an array of options. ['Answer1', 'Answer2', 'Answer3&ap ...

How many integers are there in the array?

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { NSString *title = [alertView buttonTitleAtIndex:buttonIndex]; if([title isEqualToString:@"Enter Food"]) { Food *newFood = [[Food alloc]init]; ...

Customize the inline click event using jQuery

I have a navigation with links that resemble the following: <a id="navform" href="#" tabindex="-1" onclick="mojarra.ab(this,event,'action','@form','content');return false" class=" ...

Declare a variable with global scope within a local scope

In my JavaScript project, I am attempting to refresh the page once a user is logged in by polling to continuously monitor user data. Here is the code snippet below: var check; function poll(){ return $.ajax({ url: 'http://localhost:3000/p ...

Tips for retrieving additional values from a chosen variable in Angular 10

Here is an array I have: export const Glcode = [ { id: 1, Type: 'Asset', Name: 'Cash at Head Office', code: '10018' }, { id: 2, Type: 'Asset', Name: 'POS ACCOUNT ', code: '10432' }, { ...

The JSON key has been labeled as "valid", making it difficult to access in JavaScript as demonstrated in a JSfiddle example

Initially, I transformed a Plist file (XML formatted) into JSON using an online tool. Extracting the important data from this extensive JSON file was not a challenge. Utilizing this crucial data, I am reconstructing a new JSON file that is concise and cont ...

Exploring the method of dynamically adding a row to a table on button click using Angular 2

In the midst of my Angular2 project, I am exploring the possibility of dynamically adding rows to a table when a button is clicked. While I am aware that *ngFor can achieve this, I am curious if it can be implemented only upon the clicking of a button. ...

Tips for closing 2 models in a React application

Currently, I am working on a project using ReactJs. One of the functionalities I am implementing is generating a user's gallery when the user clicks on their avatar. To achieve this, I am utilizing the react-grid-gallery package along with semantic ui ...

What is the fastest way to slice and put back together a C# List?

The scenario: I currently have a session variable that contains a list of IDs separated by pipes. These IDs are associated with views on my website and are also used for building breadcrumbs. Session["breadCrumb"] = "1001|1002|1003|1004"; If I'm vie ...

What is the ideal JavaScript framework for implementing drag-and-drop, resize, and rotation features?

I am planning to create a web application that involves images and text with user handle functionalities such as drag-and-drop, resizing, and rotating. Although I have tried using JQuery UI js to implement drag-and-drop, rotate, and resize, I have encount ...

What is the best way to store XHR data in a browser's cache?

I have been seeking a solution to locally cache an XHR request on my computer for future use. Whenever I visit an online shop, I often encounter a form in the order page that includes a field with XHR. After filling out this field, I have to submit the f ...

Conceal and reveal button with every tap

I have a scenario with 2 buttons. One button is 'disable' in one case and 'enable' in another case, but there is also a button that does not show due to the style display: none. I am using jQuery in this scenario. When I click on the e ...

Utilizing the Power of GrapesJs in Vue3

Recently, I attempted to integrate the GrapesJS editor into my Vue.js project, but encountered some difficulties. The editor was not visible in the browser, and the designated tag for the editor appeared empty. Here is my editor configuration: <template ...