0

I'm performing a get request to local server at http://localhost:3000.

I'm processing the request.body (JSON data array) through Node.JS command line.

I just want to get the name element and not the other two elements. I tried giving the index, but it didn't work.

http://localhost:3000
[ { name: 'Ankit', drag: true, jqyoui_pos: 0 },
  { name: 'Nikhil', drag: true, jqyoui_pos: 3 },
  { name: 'Ajay', drag: true, jqyoui_pos: 4 },
  { name: 'Vineet', drag: true, jqyoui_pos: 5 } ]
Tal Avissar
  • 10,088
  • 6
  • 45
  • 70
Ankit
  • 520
  • 7
  • 21

1 Answers1

3

you can filter out the names using map function. see below.

    var obj = [
           {name: 'Ankit', drag: true, jqyoui_pos: 0},
           {name: 'Nikhil', drag: true, jqyoui_pos: 3},
           {name: 'Ajay', drag: true, jqyoui_pos: 4},
           {name: 'Vineet', drag: true, jqyoui_pos: 5}
       ];


    var result = obj.map(function(a) {return a.name;});

    console.log(result);
Deendayal Garg
  • 5,030
  • 2
  • 19
  • 33