c# - Creating an object array with a different type from an existing object array in Javascript -
using lambdas , linq in c#, can create new collection type based on collection different type. instance:
var array = new list<foo> { new foo { name = "john", age = "21", title = "mr." } }; // can utilize select function create collection different type var modifiedarray = array.select(foo => new bar { title = foo.title });
i wondering if there improve way in javascript. have:
var array = [{name: 'john', age: '21', title: 'mr.'}]; var modifiedarray = []; array.foreach(function(foo){ modifiedarray.push({title: foo.title}); });
yes. can utilize array.prototype.map
var modifiedarray = array.map(function(x){ homecoming {title: x.title} });
javascript c# arrays
No comments:
Post a Comment