Turning array with objects into array with specific key from that objects? [duplicate]
up vote
-1
down vote
favorite
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();
}
);
});
});
2 days ago
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 |
up vote
-1
down vote
favorite
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();
}
);
});
});
2 days ago
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
2 days ago
Clearly he asked question without even trying himself
– siddhant sankhe
2 days ago
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
2 days ago
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
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 2 days ago
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();
}
);
});
});
2 days ago
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();
}
);
});
});
2 days ago
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
2 days ago
Clearly he asked question without even trying himself
– siddhant sankhe
2 days ago
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
2 days ago
add a comment |
Have you made any attempt at all yourself yet?
– CertainPerformance
2 days ago
Clearly he asked question without even trying himself
– siddhant sankhe
2 days ago
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
2 days ago
Have you made any attempt at all yourself yet?
– CertainPerformance
2 days ago
Have you made any attempt at all yourself yet?
– CertainPerformance
2 days ago
Clearly he asked question without even trying himself
– siddhant sankhe
2 days ago
Clearly he asked question without even trying himself
– siddhant sankhe
2 days ago
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
2 days ago
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
2 days ago
add a comment |
3 Answers
3
active
oldest
votes
up vote
2
down vote
accepted
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
2 days ago
add a comment |
up vote
1
down vote
here you go ;)
const names = objArr.map(person => person.name);
add a comment |
up vote
1
down vote
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
2 days ago
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
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
2 days ago
add a comment |
up vote
2
down vote
accepted
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
2 days ago
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
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 2 days ago
Mamun
22.4k71428
22.4k71428
1
You should really have voted to close as duplicate
– trincot
2 days ago
add a comment |
1
You should really have voted to close as duplicate
– trincot
2 days ago
1
1
You should really have voted to close as duplicate
– trincot
2 days ago
You should really have voted to close as duplicate
– trincot
2 days ago
add a comment |
up vote
1
down vote
here you go ;)
const names = objArr.map(person => person.name);
add a comment |
up vote
1
down vote
here you go ;)
const names = objArr.map(person => person.name);
add a comment |
up vote
1
down vote
up vote
1
down vote
here you go ;)
const names = objArr.map(person => person.name);
here you go ;)
const names = objArr.map(person => person.name);
answered 2 days ago
Nikita Malyschkin
1156
1156
add a comment |
add a comment |
up vote
1
down vote
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
2 days ago
add a comment |
up vote
1
down vote
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
2 days ago
add a comment |
up vote
1
down vote
up vote
1
down vote
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 2 days ago
answered 2 days ago
Mihai Alexandru-Ionut
28.9k63467
28.9k63467
You should really have voted to close as duplicate
– trincot
2 days ago
add a comment |
You should really have voted to close as duplicate
– trincot
2 days ago
You should really have voted to close as duplicate
– trincot
2 days ago
You should really have voted to close as duplicate
– trincot
2 days ago
add a comment |
Have you made any attempt at all yourself yet?
– CertainPerformance
2 days ago
Clearly he asked question without even trying himself
– siddhant sankhe
2 days ago
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
2 days ago