简体   繁体   English

如何在 java 脚本对象中执行过滤?

[英]How to perform filter in java script objects?

How to filter javascript objects based on a condition?如何根据条件过滤 javascript 对象?

I tried this, but still it fills the remaining index of the object as null, I don't want the part of object if it doesn't meet my condition,here the condition is only if the index of the object is less the selectedIndex (which is some value in my program) it should be selected, remaining are not required I tried this, but still it fills the remaining index of the object as null, I don't want the part of object if it doesn't meet my condition,here the condition is only if the index of the object is less the selectedIndex (这是我程序中的一些值)应该选择它,其余的不是必需的

console.log(Object.keys(registrationData).map((val,ind)=>{
            return (ind<=selectedIndex ) ? registrationData[val] :null
   }));

Try this尝试这个

Object
  .values(registrationData)
  .filter((value, index) => index <= selectedIndex)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM