Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Column name from array in JSON

I am getting format like this in an array here is my array=

  var array= [{"address":"Jaipur"},{"address":"Mumbai"},{"address":"Mumbai"}]

I want format like this

var array= [

    "Jaipur",
    "Mumbai"
];

what things should be done to in JSON so i can get desired array.

like image 679
Gaurav_0093 Avatar asked Nov 27 '25 03:11

Gaurav_0093


1 Answers

You can use Set to get unique values, and spread it into an array again.

var array= [{"address":"Jaipur"},{"address":"Mumbai"},{"address":"Mumbai"}];

var res = [...new Set(array.map(x => x.address))];

console.log(res)
like image 132
Egor Stambakio Avatar answered Nov 28 '25 16:11

Egor Stambakio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!