0

I get following json data from webAPI

{"data":[{"id":1,"wastageName":"BOPP at printing"},
{"id":3,"wastageName":"BOPP Production wastage"},
{"id":18,"wastageName":"LDPEE at leminatign"}]}

How can I get only list of wastageName from this data using JavaScript Or JQuery

I think we can apply Loop / each() to solve this problem.

$( "data" ).each(function( index ) {
  console.log( index + ": " + $( this ).text() );
});
Toha
  • 5
  • 3

1 Answers1

0

Using map you can achieve it

const data = {"data":[{"id":1,"wastageName":"BOPP at printing"},
{"id":3,"wastageName":"BOPP Production wastage"},
{"id":18,"wastageName":"LDPEE at leminatign"}]};

const wastageNames = data.data.map(item => item.wastageName);
console.log(wastageNames);
Sai Manoj
  • 3,809
  • 1
  • 14
  • 35