简体   繁体   中英

How to perform filter in java script objects?

How to filter javascript objects based on a condition?

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

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

Try this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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