Turning array with objects into array with specific key from that objects? [duplicate]
This question already has an answer here:
From an array of objects, extract value of a property as array
12 answers
how to get a list of key values from array of objects - JavaScript [duplicate]
2 answers
What I have is this:
const objArr = [
{name: "John", id: 1},
{name: "Marry", id: 2},
{name: "Jack", id: 3}
]
And I want this:
const names = [
"John",
"Marry",
"Jack"
]
How? Thanks!
javascript
marked as duplicate by trincot
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 at 11:29
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
From an array of objects, extract value of a property as array
12 answers
how to get a list of key values from array of objects - JavaScript [duplicate]
2 answers
What I have is this:
const objArr = [
{name: "John", id: 1},
{name: "Marry", id: 2},
{name: "Jack", id: 3}
]
And I want this:
const names = [
"John",
"Marry",
"Jack"
]
How? Thanks!
javascript
marked as duplicate by trincot
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 at 11:29
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Have you made any attempt at all yourself yet?
– CertainPerformance
Nov 19 at 11:15
Clearly he asked question without even trying himself
– siddhant sankhe
Nov 19 at 11:18
There's no need for that, I am fetching some objects from server, doing this for hours and lost my self... Actually the first answer is correct and I already tried that but did not realize that it work... No need for minuses, I am just tired... Thanks guys
– FatBoyGebajzla
Nov 19 at 11:22
add a comment |
This question already has an answer here:
From an array of objects, extract value of a property as array
12 answers
how to get a list of key values from array of objects - JavaScript [duplicate]
2 answers
What I have is this:
const objArr = [
{name: "John", id: 1},
{name: "Marry", id: 2},
{name: "Jack", id: 3}
]
And I want this:
const names = [
"John",
"Marry",
"Jack"
]
How? Thanks!
javascript
This question already has an answer here:
From an array of objects, extract value of a property as array
12 answers
how to get a list of key values from array of objects - JavaScript [duplicate]
2 answers
What I have is this:
const objArr = [
{name: "John", id: 1},
{name: "Marry", id: 2},
{name: "Jack", id: 3}
]
And I want this:
const names = [
"John",
"Marry",
"Jack"
]
How? Thanks!
This question already has an answer here:
From an array of objects, extract value of a property as array
12 answers
how to get a list of key values from array of objects - JavaScript [duplicate]
2 answers
javascript
javascript
asked Nov 19 at 11:14
FatBoyGebajzla
327
327
marked as duplicate by trincot
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 at 11:29
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by trincot
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 at 11:29
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Have you made any attempt at all yourself yet?
– CertainPerformance
Nov 19 at 11:15
Clearly he asked question without even trying himself
– siddhant sankhe
Nov 19 at 11:18
There's no need for that, I am fetching some objects from server, doing this for hours and lost my self... Actually the first answer is correct and I already tried that but did not realize that it work... No need for minuses, I am just tired... Thanks guys
– FatBoyGebajzla
Nov 19 at 11:22
add a comment |
Have you made any attempt at all yourself yet?
– CertainPerformance
Nov 19 at 11:15
Clearly he asked question without even trying himself
– siddhant sankhe
Nov 19 at 11:18
There's no need for that, I am fetching some objects from server, doing this for hours and lost my self... Actually the first answer is correct and I already tried that but did not realize that it work... No need for minuses, I am just tired... Thanks guys
– FatBoyGebajzla
Nov 19 at 11:22
Have you made any attempt at all yourself yet?
– CertainPerformance
Nov 19 at 11:15
Have you made any attempt at all yourself yet?
– CertainPerformance
Nov 19 at 11:15
Clearly he asked question without even trying himself
– siddhant sankhe
Nov 19 at 11:18
Clearly he asked question without even trying himself
– siddhant sankhe
Nov 19 at 11:18
There's no need for that, I am fetching some objects from server, doing this for hours and lost my self... Actually the first answer is correct and I already tried that but did not realize that it work... No need for minuses, I am just tired... Thanks guys
– FatBoyGebajzla
Nov 19 at 11:22
There's no need for that, I am fetching some objects from server, doing this for hours and lost my self... Actually the first answer is correct and I already tried that but did not realize that it work... No need for minuses, I am just tired... Thanks guys
– FatBoyGebajzla
Nov 19 at 11:22
add a comment |
3 Answers
3
active
oldest
votes
Use Array.prototype.map() to return only the name property.
The
map()
method creates a new array with the results of calling a provided function on every element in the calling array.
const objArr = [
{name: "John", id: 1},
{name: "Marry", id: 2},
{name: "Jack", id: 3}
]
const names = objArr.map(p => p.name);
console.log(names);
1
You should really have voted to close as duplicate
– trincot
Nov 19 at 11:30
add a comment |
here you go ;)
const names = objArr.map(person => person.name);
add a comment |
Just use map
method in combination with destructuring by passing a callback provided function as argument.
const objArr = [{name: "John", id: 1}, {name: "Marry", id: 2}, {name: "Jack", id: 3}]
console.log(objArr.map(({name}) => name));
You should really have voted to close as duplicate
– trincot
Nov 19 at 11:30
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use Array.prototype.map() to return only the name property.
The
map()
method creates a new array with the results of calling a provided function on every element in the calling array.
const objArr = [
{name: "John", id: 1},
{name: "Marry", id: 2},
{name: "Jack", id: 3}
]
const names = objArr.map(p => p.name);
console.log(names);
1
You should really have voted to close as duplicate
– trincot
Nov 19 at 11:30
add a comment |
Use Array.prototype.map() to return only the name property.
The
map()
method creates a new array with the results of calling a provided function on every element in the calling array.
const objArr = [
{name: "John", id: 1},
{name: "Marry", id: 2},
{name: "Jack", id: 3}
]
const names = objArr.map(p => p.name);
console.log(names);
1
You should really have voted to close as duplicate
– trincot
Nov 19 at 11:30
add a comment |
Use Array.prototype.map() to return only the name property.
The
map()
method creates a new array with the results of calling a provided function on every element in the calling array.
const objArr = [
{name: "John", id: 1},
{name: "Marry", id: 2},
{name: "Jack", id: 3}
]
const names = objArr.map(p => p.name);
console.log(names);
Use Array.prototype.map() to return only the name property.
The
map()
method creates a new array with the results of calling a provided function on every element in the calling array.
const objArr = [
{name: "John", id: 1},
{name: "Marry", id: 2},
{name: "Jack", id: 3}
]
const names = objArr.map(p => p.name);
console.log(names);
const objArr = [
{name: "John", id: 1},
{name: "Marry", id: 2},
{name: "Jack", id: 3}
]
const names = objArr.map(p => p.name);
console.log(names);
const objArr = [
{name: "John", id: 1},
{name: "Marry", id: 2},
{name: "Jack", id: 3}
]
const names = objArr.map(p => p.name);
console.log(names);
answered Nov 19 at 11:17
Mamun
24.7k71428
24.7k71428
1
You should really have voted to close as duplicate
– trincot
Nov 19 at 11:30
add a comment |
1
You should really have voted to close as duplicate
– trincot
Nov 19 at 11:30
1
1
You should really have voted to close as duplicate
– trincot
Nov 19 at 11:30
You should really have voted to close as duplicate
– trincot
Nov 19 at 11:30
add a comment |
here you go ;)
const names = objArr.map(person => person.name);
add a comment |
here you go ;)
const names = objArr.map(person => person.name);
add a comment |
here you go ;)
const names = objArr.map(person => person.name);
here you go ;)
const names = objArr.map(person => person.name);
answered Nov 19 at 11:16
Nikita Malyschkin
1136
1136
add a comment |
add a comment |
Just use map
method in combination with destructuring by passing a callback provided function as argument.
const objArr = [{name: "John", id: 1}, {name: "Marry", id: 2}, {name: "Jack", id: 3}]
console.log(objArr.map(({name}) => name));
You should really have voted to close as duplicate
– trincot
Nov 19 at 11:30
add a comment |
Just use map
method in combination with destructuring by passing a callback provided function as argument.
const objArr = [{name: "John", id: 1}, {name: "Marry", id: 2}, {name: "Jack", id: 3}]
console.log(objArr.map(({name}) => name));
You should really have voted to close as duplicate
– trincot
Nov 19 at 11:30
add a comment |
Just use map
method in combination with destructuring by passing a callback provided function as argument.
const objArr = [{name: "John", id: 1}, {name: "Marry", id: 2}, {name: "Jack", id: 3}]
console.log(objArr.map(({name}) => name));
Just use map
method in combination with destructuring by passing a callback provided function as argument.
const objArr = [{name: "John", id: 1}, {name: "Marry", id: 2}, {name: "Jack", id: 3}]
console.log(objArr.map(({name}) => name));
const objArr = [{name: "John", id: 1}, {name: "Marry", id: 2}, {name: "Jack", id: 3}]
console.log(objArr.map(({name}) => name));
const objArr = [{name: "John", id: 1}, {name: "Marry", id: 2}, {name: "Jack", id: 3}]
console.log(objArr.map(({name}) => name));
edited Nov 19 at 11:23
answered Nov 19 at 11:16
Mihai Alexandru-Ionut
29.4k63769
29.4k63769
You should really have voted to close as duplicate
– trincot
Nov 19 at 11:30
add a comment |
You should really have voted to close as duplicate
– trincot
Nov 19 at 11:30
You should really have voted to close as duplicate
– trincot
Nov 19 at 11:30
You should really have voted to close as duplicate
– trincot
Nov 19 at 11:30
add a comment |
Have you made any attempt at all yourself yet?
– CertainPerformance
Nov 19 at 11:15
Clearly he asked question without even trying himself
– siddhant sankhe
Nov 19 at 11:18
There's no need for that, I am fetching some objects from server, doing this for hours and lost my self... Actually the first answer is correct and I already tried that but did not realize that it work... No need for minuses, I am just tired... Thanks guys
– FatBoyGebajzla
Nov 19 at 11:22