Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在javascript中从对象获取多个distint值_Javascript_Node.js_Mongoose - Fatal编程技术网

在javascript中从对象获取多个distint值

在javascript中从对象获取多个distint值,javascript,node.js,mongoose,Javascript,Node.js,Mongoose,有人能告诉我如何从对象中获得唯一的价值吗?到目前为止,我能通过这些方法获得它 const address = await Property.find({address:{$regex: req.body.tag, $options: 'i'}}).where('offerType').equals(req.params.type).select('city address offerType district property_id').lean(); const district = awai

有人能告诉我如何从对象中获得唯一的价值吗?到目前为止,我能通过这些方法获得它

const address = await Property.find({address:{$regex: req.body.tag, $options: 'i'}}).where('offerType').equals(req.params.type).select('city address offerType district property_id').lean();
const district = await Property.find({district:{$regex:req.body.tag,$options: 'i'}}).where('offerType').equals(req.params.type).select('city  district ').lean();
let data =[]



district.forEach(element => {
  var i = data.findIndex(x => (x.district == element.district && x.city == element.city));
  if(i <= -1){
  
    data.push({address: '',district:element.district,city:element.city,offerType:element.offerType})
  }
 });
 console.log(data)

 address.forEach(element => {
  var i = data.findIndex(x => (x.address == element.address && x.city == element.city));
  if(i <= -1){
    data.push({address: element.address,district:element.district,city:element.city,offerType:element.offerType})
  }
 });
当我试图获得唯一值时,问题就开始了。我能够得到唯一的地区,但我的地址有问题

  demoCheck.forEach(element => {
  const  i = data.findIndex(x => (x.district == element.district && x.city == element.city));
  const  j = data.findIndex(j => (j.address == element.address && j.city == element.city));
  if(i <= -1){
    data.push({address: '',district:element.district,city:element.city,offerType:element.offerType})
  }else if (j <= -1){

    data.push({address:element.address,district:'',city:element.city,offerType:element.offerType})
  }
 });
demoCheck.forEach(元素=>{
const i=data.findIndex(x=>(x.district==element.district&&x.city==element.city));
const j=data.findIndex(j=>(j.address==element.address&&j.city==element.city));
如果(i)
  demoCheck.forEach(element => {
  const  i = data.findIndex(x => (x.district == element.district && x.city == element.city));
  const  j = data.findIndex(j => (j.address == element.address && j.city == element.city));
  if(i <= -1){
    data.push({address: '',district:element.district,city:element.city,offerType:element.offerType})
  }else if (j <= -1){

    data.push({address:element.address,district:'',city:element.city,offerType:element.offerType})
  }
 });