javascript - Skip and return objects from list of object using Lodash/Underscore -
i need perform operation similar next written in c#:
int[] items = { 1, 2, 3, 4, 5, 6, 7 }; var = items.skip(2).take(3);
which homecoming 3, 4 , 5
similarly need skip records list of object
$scope.myobject = [ { editable: true, name: "daniel test", site: "se100"}, { editable: true, name: "test new", site: "se100"}, { editable: false, name: "test", site: "se100"} ]
i need skip first record , remaining records, meaning 1-nth record
how can using lodash/underscore?
first , rest should trick:
var = _.first( _.rest(items, 2), 3);
and rest on it's own can used skip first record:
$scope.allbutthefirst = _.rest( $scope.myobject, 1)
chaining can used create statement more pleasing eye , hence improve transparency:
var = _.chain(items) .rest(2) .first(3) .value();
javascript underscore.js lodash
No comments:
Post a Comment