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!










share|improve this question













marked as duplicate by trincot javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

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















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!










share|improve this question













marked as duplicate by trincot javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

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













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!










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 days ago









FatBoyGebajzla

327




327




marked as duplicate by trincot javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

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 javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

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


















  • 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












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);








share|improve this answer

















  • 1




    You should really have voted to close as duplicate
    – trincot
    2 days ago


















up vote
1
down vote













here you go ;)



const names = objArr.map(person => person.name);





share|improve this answer




























    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));








    share|improve this answer























    • You should really have voted to close as duplicate
      – trincot
      2 days ago


















    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);








    share|improve this answer

















    • 1




      You should really have voted to close as duplicate
      – trincot
      2 days ago















    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);








    share|improve this answer

















    • 1




      You should really have voted to close as duplicate
      – trincot
      2 days ago













    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);








    share|improve this answer












    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);






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered 2 days ago









    Mamun

    22.4k71428




    22.4k71428








    • 1




      You should really have voted to close as duplicate
      – trincot
      2 days ago














    • 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












    up vote
    1
    down vote













    here you go ;)



    const names = objArr.map(person => person.name);





    share|improve this answer

























      up vote
      1
      down vote













      here you go ;)



      const names = objArr.map(person => person.name);





      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        here you go ;)



        const names = objArr.map(person => person.name);





        share|improve this answer












        here you go ;)



        const names = objArr.map(person => person.name);






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 days ago









        Nikita Malyschkin

        1156




        1156






















            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));








            share|improve this answer























            • You should really have voted to close as duplicate
              – trincot
              2 days ago















            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));








            share|improve this answer























            • You should really have voted to close as duplicate
              – trincot
              2 days ago













            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));








            share|improve this answer














            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));






            share|improve this answer














            share|improve this answer



            share|improve this answer








            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


















            • 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



            Popular posts from this blog

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            SQL update select statement

            'app-layout' is not a known element: how to share Component with different Modules