只需要包含c和的话 let todos = [{ _id: '001', tags: ['a', 'b', 'c', 'd'], judge:0 }, { _id: '002', tags: ['c', 'e', 'd', 'f'], judge:0 }, { _id: '003', tags: ['c', 'r', 'g', 'h'], judge:0 }, { _id: '004', tags: ['c', 'z', 'd', 'y'], judge:0 }] for (let i=0;i<todos.length;i++) { for (let j=0;j<todos[i].tags.length;j++) { if (todos[i].tags[j]=='c'||todos[i].tags[j]=='d') { todos[i].judge+=1 } } if (todos[i].judge==2) { console.log(true) } } console.log(todos)
求教,如何查询数组中是否包含数组的问题?todos:[{ _id: '001', tags: ['a', 'b', 'c', 'd'] }, { _id: '002', tags: ['c', 'e', 'd', 'f'] }, { _id: '003', tags: ['c', 'r', 'g', 'h'] }, { _id: '004', tags: ['c', 'z', 'd', 'y'] }] // 如何查询 tags 中包含 ['c','d'] 的记录 db.collection('todos').where({ tags: 包含['c', 'd'] }).get() 求教,如何查询 tags 中包含 ['c','d'] 的记录,谢谢!
2020-12-31