Can I remove 'null' from my drop down selection variable

淺唱寂寞╮ 提交于 2019-12-11 16:59:24

问题


I have a multi select drop down allowing my user to select multiple A, B and/or C options, using react-select. Each time one is selected, I want it to be added to a 'choice' variable to keep record. I have this working, but since I have to declare my variable first, it is holding 'null' inside the variable. How do I get rid of this? Code below.

handleChange = (selectedChoice) => {
this.setState({ selectedChoice });
for (var i =0; i < selectedChoice.length; i++) {
   var filter = null;
   filter +=(selectedChoice[i].value); //removing the plus just resets it to last chosen option
    }
  console.log(filter);
  }

example of what it prints: nullAC


回答1:


The solution to this was posted in the comments by Yury Tarabanko.

var filter = ''

For good practice console.log would also not be in that position within the code.



来源:https://stackoverflow.com/questions/53263601/can-i-remove-null-from-my-drop-down-selection-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!