简体   繁体   English

Array.prototype.join() 在反应 useState 中不起作用

[英]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.

相关问题 如何在reactjs中使用array.prototype.join - How to using array.prototype.join in reactjs Array.prototype.join在IE 8中不起作用 - Array.prototype.join not working in IE 8 在Javascript中,Array.join真的是Array.prototype.join吗? - In Javascript, is Array.join really Array.prototype.join? 为什么 Array.prototype.join() 会展平任意深度的数组? - Why does Array.prototype.join() flatten an array of any depth? 类似于Java中的Array.prototype.join的地图或平面图 - Map or flatmap that works like Array.prototype.join in Javascript 我怎样才能真正理解'Array.prototype.join'的方法 - How can I really understand the method of 'Array.prototype.join' 除了Array.prototype.join()以外,还有没有更短的方法将数组连接到一个字符串? - Is there a shorter way to join an array to one string besides Array.prototype.join()? React setState 不适用于 array.prototype.splice - React setState doesn't work with array.prototype.splice 我尝试编写自己的Array.prototype.join()有什么问题? - What's wrong with my attempt to write my own Array.prototype.join()? 为什么 Array.prototype.map 会忽略稀疏数组中的空槽,而 Array.prototype.join 不会? - Why does Array.prototype.map ignore empty slots in a sparse array whereas Array.prototype.join does not?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM