提交 f761cd11 编写于 作者: Q qq_42700109

Sat Nov 11 01:09:00 CST 2023 inscode

上级 ef53fd87
run = "index.html"
language = "node"
[env]
PATH = "/root/${PROJECT_DIR}/.config/npm/node_global/bin:/root/${PROJECT_DIR}/node_modules/.bin:${PATH}"
XDG_CONFIG_HOME = "/root/.config"
npm_config_prefix = "/root/${PROJECT_DIR}/.config/npm/node_global"
\ No newline at end of file
npm_config_prefix = "/root/${PROJECT_DIR}/.config/npm/node_global"
[debugger]
program = "main.js"
// 对象数组筛选condition={dataKey:筛选条件。。。},data=需要筛选的数据
let data = [ {
name: '国-红楼梦',
price: 123,
stock: 108
}, {
name: '国-西游记',
price: 99,
stock: 151
}, {
name: '国-水浒传',
price: 708,
stock: 72
}, {
name: '国-三国演义',
price: 58,
stock: 72
}, {
name: '外-荆棘鸟',
price: 45,
stock: 65
}, {
name: '外-格列佛游记',
price: 69,
stock: 151
}, {
name: '外-荷马史诗',
price: 48,
stock: 123
} ]
function filter(condition, data){
return data.filter( item => {
return Object.keys( condition ).every( key => {
return String( item[ key ] ).toLowerCase().includes(
String( condition[ key ] ).trim().toLowerCase() )
} )
} )
}
//无条件
var condition={name: '',price: ''};
var aa = filter(condition,data);
console.log("=== 无条件 ===");
console.log(aa);
//单条件
var condition={name: ''};
var bb = filter(condition,data);
console.log("=== 单条件 ===");
console.log(bb);
//多条件
var condition={name: '',stock: 72};
var cc = filter(condition,data);
console.log("=== 多条件 ===");
console.log(cc);
let array = [
{
date: '2022-05-02',
name: 'cuclife',
status: 'success',
tag: '70',
band:['R','B']
},
{
date: '2022-05-04',
name: 'Lily',
status: 'fail',
tag: '50',
band:['R','G']
},
{
date: '2022-05-01',
name: 'Kevin',
status: 'success',
tag: '20',
band:['R','G','B']
},
{
date: '2022-05-02',
name: 'Kevin',
status: 'success',
tag: '70',
band:['R','G','B','RE']
}
];
let filterNames = ['Lily'];
let filterBand = ['R','G'];
let filterTag = ['50','70'];
let result = array.filter((a,i)=>{
return (filterNames.some(f => (f === a.name)) && filterTag.some(f => (f === a.tag)) || filterBand.some(f => (a.band.includes(f))) )
});
console.log(result);
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册