Using array map to filter results with if conditional

前端 未结 3 2096
孤街浪徒
孤街浪徒 2020-12-03 13:01

I am trying to use an array map to filter a object a bit further to prepare it to send to the server to for saving. I can filter to 1 key value, which is great, but I want t

3条回答
  •  甜味超标
    2020-12-03 13:49

    Here's some info if someone comes upon this in 2019.

    I think reduce vs map + filter might be somewhat dependent on what you need to loop through. Not sure on this but reduce does seem to be slower.

    One thing is for sure - if you're looking for performance improvements the way you write the code is extremely important!

    Here a JS perf test that shows the massive improvements when typing out the code fully rather than checking for "falsey" values (e.g. if (string) {...}) or returning "falsey" values where a boolean is expected.

    Hope this helps someone

提交回复
热议问题