js. splice returns removed item?
.splice
does return the removed item. However, it also manipulates the array internally. This prevents you from chaining anything to .splice
; you must do two separate calls:
value = value.split(',');
value.splice(1, 1);
console.log(value.join(','));
If you do value = value.splice(...)
, value
is overridden, and the array is lost!
.splice
is in-place, so just remove the value =
and it'll modify the array like you'd expect:
> var value = "c, a, b";
> value = value.split(', ');
["c", "a", "b"]
> value.splice(1, 1);
["a"]
> value
["c", "b"]
var a = ["1","2","3"]
a.splice(1,1) && a
a=["1","3"]