[英]Array.prototype.join() doesn't work in react useState
I'm trying to use join()
, but it just doesn't work, the console send a warning message saying Uncaught TypeError: calcNumbers.join is not a function
;我正在尝试使用
join()
,但它不起作用,控制台发送一条警告消息说Uncaught TypeError: calcNumbers.join is not a function
; see the code below.请参阅下面的代码。
import { useState } from "react";
const [calcNumbers, setCalcNumbers] = useState(['1', '2', '3','4'])
setCalcNumbers(calcNumbers.join(''))
It's working for first time because you have array, after join method it changed to string, string type has not join('') method.它是第一次工作,因为你有数组,在加入方法之后它变成了字符串,字符串类型没有加入('')方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.