Remove column name from array in JSON
5 answers
var array= [{"address":"Jaipur"},{"address":"Mumbai"},{"address":"Mumbai"}];
var address=[];
$.each(array,function(add,val){
address.push(val.address);
});
var address = Array.from(new Set(address));
console.log(address);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
+2
source to share
You can reduce
array:
var array= [{"address":"Jaipur"},{"address":"Mumbai"},{"address":"Mumbai"}];
var formatedArray = array.reduce((output, item) => {
if(!output.includes(item.address)) {
output.push(item.address)
}
return output
}, [])
console.log(formatedArray)
+1
source to share
string json = DataTableToJSON(dt_main);
jsonnew = @"{""Data"":" + json + "}";
private static string DataTableToJSON(DataTable table)
{
List<string[]> result = table.Rows
.Cast<DataRow>()
.Select(row => row.ItemArray
.Select(x => x.ToString())
.ToArray())
.ToList();
JavaScriptSerializer serializer = new JavaScriptSerializer();
return serializer.Serialize(result);
//------another method----------------
//ArrayList arr = new ArrayList();
//List<ArrayList> list = new List<ArrayList>();
//foreach (DataRow row in table.Rows)
//{
// arr = new ArrayList();
// foreach (DataColumn col in table.Columns)
// {
// arr.Insert(col.Ordinal, row[col]);
// }
// list.Add(arr);
//}
// JavaScriptSerializer serializer = new JavaScriptSerializer();
// return serializer.Serialize(list);
}
-1
source to share