So I want to convert this array retrieved from a database to just an array of string values:
Array:[{"userid":"c"},{"userid":"d"}]
Expected results:["c","d"]
So I want to convert this array retrieved from a database to just an array of string values:
Array:[{"userid":"c"},{"userid":"d"}]
Expected results:["c","d"]
you can use the map
function
result = myArray.map(function(item){ return item.userid; })
If you need this conversions on javascript side, you should keep in mind, that if there would be a lot of items, the performance might be rather bad. May be it would be better to change logick of gathering the first array.
For conversion you could try this:
Data = [{"userid":"c"},{"userid":"d"}];
arr = [];
for(i in Data){
arr.push(Data[i].userid);
}
console.log(arr);