Turning array with objects into array with specific key from that objects? [duplicate]












-1















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
















-1















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














-1












-1








-1








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 Nov 19 at 11:14









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


















  • 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












3 Answers
3






active

oldest

votes


















2














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
    Nov 19 at 11:30



















1














here you go ;)



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





share|improve this answer





























    1














    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
      Nov 19 at 11:30


















    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    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
      Nov 19 at 11:30
















    2














    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
      Nov 19 at 11:30














    2












    2








    2






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














    • 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













    1














    here you go ;)



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





    share|improve this answer


























      1














      here you go ;)



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





      share|improve this answer
























        1












        1








        1






        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 Nov 19 at 11:16









        Nikita Malyschkin

        1136




        1136























            1














            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
              Nov 19 at 11:30
















            1














            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
              Nov 19 at 11:30














            1












            1








            1






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


















            • 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



            Popular posts from this blog

            Volksrepublik China

            How to test boost logger output in unit testing?

            Write to the output between two pipeline