去除一个对象数组里不需要的键值对 生成新的数组
<script>
let a=[
{
createTime: "2020-06-19 14:48:57",
delFlag: 1,
goodsCategory: "1273869332852719616",
goodsCode: "123456",
goodsName: "感冒灵颗粒",
goodsPic: "1273870309353799680",
goodsPrice: 9,
id: "1273870363699396608",
industryCategory: 2,
isShelf: 1,
itemNumber: "",
merchantId: "1239217264236613632",
merchantUserId: "1273867462012780544",
name: null,
saleRemark: null,
salesNum: 13,
sort: 1,
source: 1,
stockNum: 99986,
storeId: "1273867968638566400",
systemCategory: null,
unit: "",
updateTime: "2020-11-25 12:26:49",
},
{
createTime: "2020-06-19 14:55:25",
delFlag: 1,
goodsCategory: "1273869379375939584",
goodsCode: "5",
goodsName: "阿莫西林胶囊",
goodsPic: "1273871948731072512",
goodsPrice: 7,
id: "1273871990716055552",
industryCategory: 2,
isShelf: 1,
itemNumber: "",
merchantId: "1239217264236613632",
merchantUserId: "1273867462012780544",
name: null,
saleRemark: null,
salesNum: 2,
sort: 1,
source: 1,
stockNum: 99997,
storeId: "1273867968638566400",
systemCategory: null,
unit: "",
updateTime: "2020-11-21 17:47:27",
},
{
createTime: "2020-06-19 14:55:57",
delFlag: 1,
goodsCategory: "1273869379375939584",
goodsCode: "4",
goodsName: "蒲地蓝消炎片",
goodsPic: "1273872070277808128",
goodsPrice: 5,
id: "1273872125143498752",
industryCategory: 2,
isShelf: 1,
itemNumber: "",
merchantId: "1239217264236613632",
merchantUserId: "1273867462012780544",
name: null,
saleRemark: null,
salesNum: 1,
sort: 1,
source: 1,
stockNum: 99998,
storeId: "1273867968638566400",
systemCategory: null,
unit: "",
updateTime: "2020-11-25 10:33:42",
},
];
var newObj = {};
var newArr = [];
a.forEach(function(item,i){
for ( var key in item) {
if(key != 'goodsName'&& key != 'salesNum'){
newObj[key] = item[key];
}
}
newArr.push(newObj);
newObj = {};
});
console.log(newArr);
</script>