简体   繁体   English

使用REST使用rest / spread运算符删除索引

[英]Delete index using rest/spread operator using JS

I have the following scenario where I need an index deleted. 我在以下情况下需要删除索引。

JS: JS:

this.state = {
      rangeValue: this.props.rangeSlider && [
        this.props.rangeValue[0],
        this.props.rangeValue[1],
        this.props.rangeValue[2]
      ],
    };


<Range 
   defaultValue={
   this.props.rangeValue[2] ? [...this.state.rangeValue] : [...this.state.rangeValue] //minus last index in my array (this.props.rangeValue[2])
            }
          />

You can remove the last element by using slice 您可以使用slice删除最后一个元素

this.state.rangeValue.slice(0,-1);

Your code : 您的代码:

<Range
  defaultValue={
    this.props.rangeValue[2] ? [...this.state.rangeValue] : this.state.rangeValue.slice(0, -1)
  }
/>

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

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