Toggle values into and out of an array in Javascript

前端 未结 4 942
臣服心动
臣服心动 2021-02-19 05:08

I want to have a simple array of values, ie

var simpleArray = [\"SE1\",\"SE2\",\"SE3\"];

I want to check this array when an action happens (a c

4条回答
  •  再見小時候
    2021-02-19 05:22

    my ES* variant

    const toggleArrayValue = (arrayList, arrayValue) =>
      arrayList.includes(arrayValue)
        ? arrayList.filter(el => el !== arrayValue)
        : [...arrayList, arrayValue]
    

提交回复
热议问题