【问题标题】:Filter array_values in javascript and stored it in new variable在javascript中过滤array_values并将其存储在新变量中
【发布时间】:2019-06-18 07:00:48
【问题描述】:

如何过滤last_login = null并获取array_values?

 //   for(let y=0; y<this.searchLogin.length; y++ ){
 //      for(let i=0; i<this.list.length; i++){
 //         if(this.list[y].last_login == null ){
 //           this.retval.push(this.newval[i])
 //            } else {
 //             null
 //             }
 //        }
 //    }

 //   this.newval = []
 //    this.newval = this.retval
 //    this.retval = []

更新:

var output = [];
  for (var i=0; i < this.list.length ; ++i){
    for(let i=0; i<this.list.length; i++){
      if(this.list[y].profile.last_login == null ){
        output.push(this.list[i]);
      return output;
    }
  }
}

console.log('this is list',this.list) 输出:

【问题讨论】:

标签: javascript mysql loops vue.js console


【解决方案1】:

您提供的有限信息确实很难理解发生了什么,但可能是您将this.retval 分配给this.newval,然后清空this.retval。假设您在此之后返回 this.newval 可能是一个问题。数组是 Javascript 中的参考值,因此您基本上也将 this.newval 设置为一个空数组。在 Javascript 中,乍一看并不是 100% 清楚某物是参考,因此当您不希望值更改时遇到问题时,最好研究一下是否是这种情况。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-21
    • 1970-01-01
    • 2021-06-22
    • 2021-07-16
    • 2021-12-01
    • 1970-01-01
    • 2016-10-19
    • 1970-01-01
    相关资源
    最近更新 更多