Lodash,满足要求的对象

时间:2017-05-17 09:19:21

标签: javascript typescript lodash

示例:

head

如何将Id不为null的所有对象转换为新数组?

预期产出:

<style type="text/css">

1 个答案:

答案 0 :(得分:1)

尝试使用_.filter

&#13;
&#13;
var Animals = [{Name: 'Dog', Id: 0},{Name: 'Cat', Id: 1},{Name: 'Mouse', Id:null}]
var newArray =_.filter(Animals ,a=> a.Id != null)
console.log(newArray)
&#13;
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.11.2/lodash.min.js"></script>
&#13;
&#13;
&#13;