Array map
use of Array.map()
by Varun Sukheja
HTML
<script src="https://cdn.jsdelivr.net/gh/eu81273/jsfiddle-console/console.js"></script>
JavaScript
const userList = [
{ name: 'Alex', age: 51, country: 'USA' },
{ name: 'Varun', age: 26, country: 'India' },
{ name: 'Raman', age: 16, country: 'India' },
{ name: 'Max', age: 11, country: 'USA' },
{ name: 'Vishal', age: 32, country: 'India' }
];
/* Get only names in new array */
const userNames = userList.map(user => {
return user.name;
});
/* Printing variable userNames */
console.log('Array of User Names:-', userNames);