Given these two arrays:
$scope.city= [{id :'NewYork' } , {id : 'Chicago'}];
$scope.color = [{id : 'blue' } , {id : 'Green'}];
I need only the values of both arrays like this:
$scope.string = 'NewYork_Chicago_blue_Green';
Use Array#map
to convert each array to an array of strings, then Array#concat
them, and Array#join
with underscore:
var city = [ {id :'NewYork' } , {id : 'Chicago'}];
var color = [{id : 'blue' } , {id : 'Green'}];
function getId(o) {
return o.id;
}
var result = city.map(getId).concat(color.map(getId)).join('_');
console.log(result);
Try these steps :
Working demo :
var city= [ {id :'NewYork' } , {id : 'Chicago'}];
var color = [{id : 'blue' } , {id : 'Green'}];
var cityColor = city.concat(color);
var arr = [];
for (var i in cityColor) {
arr.push(cityColor[i].id);
}
var str = arr.join('_');
console.log(str);